From 61184129efe8367ebf861e354e7c8e3cee933a4b Mon Sep 17 00:00:00 2001 From: Koakuma Date: Fri, 16 Aug 2024 09:01:58 +0700 Subject: [PATCH 1/3] [SPARC] Loosen assertions in printOperand for inline asm operands Inline asm operands could contain any kind of relocation in its operands, so bypass the checks so that it can be performed against the instructions inside the inline asm string instead. Fixes https://github.com/llvm/llvm-project/issues/103493 --- llvm/lib/Target/Sparc/SparcAsmPrinter.cpp | 18 ++++++++++-------- llvm/test/CodeGen/SPARC/inlineasm.ll | 10 ++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp b/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp index 6855471840e9d..8a19ae9ad175f 100644 --- a/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp +++ b/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp @@ -31,6 +31,7 @@ #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/TargetRegistry.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -317,10 +318,11 @@ void SparcAsmPrinter::printOperand(const MachineInstr *MI, int opNum, #ifndef NDEBUG // Verify the target flags. if (MO.isGlobal() || MO.isSymbol() || MO.isCPI()) { - if (MI->getOpcode() == SP::CALL) + unsigned Opc = MI->getOpcode(); + if (Opc == SP::CALL) assert(TF == SparcMCExpr::VK_Sparc_None && "Cannot handle target flags on call address"); - else if (MI->getOpcode() == SP::SETHIi) + else if (Opc == SP::SETHIi) assert((TF == SparcMCExpr::VK_Sparc_HI || TF == SparcMCExpr::VK_Sparc_H44 || TF == SparcMCExpr::VK_Sparc_HH @@ -331,28 +333,28 @@ void SparcAsmPrinter::printOperand(const MachineInstr *MI, int opNum, || TF == SparcMCExpr::VK_Sparc_TLS_IE_HI22 || TF == SparcMCExpr::VK_Sparc_TLS_LE_HIX22) && "Invalid target flags for address operand on sethi"); - else if (MI->getOpcode() == SP::TLS_CALL) + else if (Opc == SP::TLS_CALL) assert((TF == SparcMCExpr::VK_Sparc_None || TF == SparcMCExpr::VK_Sparc_TLS_GD_CALL || TF == SparcMCExpr::VK_Sparc_TLS_LDM_CALL) && "Cannot handle target flags on tls call address"); - else if (MI->getOpcode() == SP::TLS_ADDrr) + else if (Opc == SP::TLS_ADDrr) assert((TF == SparcMCExpr::VK_Sparc_TLS_GD_ADD || TF == SparcMCExpr::VK_Sparc_TLS_LDM_ADD || TF == SparcMCExpr::VK_Sparc_TLS_LDO_ADD || TF == SparcMCExpr::VK_Sparc_TLS_IE_ADD) && "Cannot handle target flags on add for TLS"); - else if (MI->getOpcode() == SP::TLS_LDrr) + else if (Opc == SP::TLS_LDrr) assert(TF == SparcMCExpr::VK_Sparc_TLS_IE_LD && "Cannot handle target flags on ld for TLS"); - else if (MI->getOpcode() == SP::TLS_LDXrr) + else if (Opc == SP::TLS_LDXrr) assert(TF == SparcMCExpr::VK_Sparc_TLS_IE_LDX && "Cannot handle target flags on ldx for TLS"); - else if (MI->getOpcode() == SP::XORri) + else if (Opc == SP::XORri) assert((TF == SparcMCExpr::VK_Sparc_TLS_LDO_LOX10 || TF == SparcMCExpr::VK_Sparc_TLS_LE_LOX10) && "Cannot handle target flags on xor for TLS"); - else + else if (Opc != SP::INLINEASM && Opc != SP::INLINEASM_BR) assert((TF == SparcMCExpr::VK_Sparc_LO || TF == SparcMCExpr::VK_Sparc_M44 || TF == SparcMCExpr::VK_Sparc_L44 diff --git a/llvm/test/CodeGen/SPARC/inlineasm.ll b/llvm/test/CodeGen/SPARC/inlineasm.ll index 14ea0a2a12602..e2853f03a002e 100644 --- a/llvm/test/CodeGen/SPARC/inlineasm.ll +++ b/llvm/test/CodeGen/SPARC/inlineasm.ll @@ -152,3 +152,13 @@ define i64 @test_twinword(){ %1 = tail call i64 asm sideeffect "rd %asr5, ${0:L} \0A\09 srlx ${0:L}, 32, ${0:H}", "={i0}"() ret i64 %1 } + +; CHECK-LABEL: test_symbol: +; CHECK: ba,a brtarget +define void @test_symbol() { +Entry: + call void asm sideeffect "ba,a ${0}", "X"(ptr @brtarget) + unreachable +} + +declare void @brtarget() From 066acd76eec55a8106dcdd16b65137cee8f34f08 Mon Sep 17 00:00:00 2001 From: Koakuma Date: Tue, 20 Aug 2024 09:52:26 +0700 Subject: [PATCH 2/3] Remove the asserts entirely --- llvm/lib/Target/Sparc/SparcAsmPrinter.cpp | 52 ----------------------- 1 file changed, 52 deletions(-) diff --git a/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp b/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp index 8a19ae9ad175f..8401b42ea189f 100644 --- a/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp +++ b/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp @@ -315,58 +315,6 @@ void SparcAsmPrinter::printOperand(const MachineInstr *MI, int opNum, const MachineOperand &MO = MI->getOperand (opNum); SparcMCExpr::VariantKind TF = (SparcMCExpr::VariantKind) MO.getTargetFlags(); -#ifndef NDEBUG - // Verify the target flags. - if (MO.isGlobal() || MO.isSymbol() || MO.isCPI()) { - unsigned Opc = MI->getOpcode(); - if (Opc == SP::CALL) - assert(TF == SparcMCExpr::VK_Sparc_None && - "Cannot handle target flags on call address"); - else if (Opc == SP::SETHIi) - assert((TF == SparcMCExpr::VK_Sparc_HI - || TF == SparcMCExpr::VK_Sparc_H44 - || TF == SparcMCExpr::VK_Sparc_HH - || TF == SparcMCExpr::VK_Sparc_LM - || TF == SparcMCExpr::VK_Sparc_TLS_GD_HI22 - || TF == SparcMCExpr::VK_Sparc_TLS_LDM_HI22 - || TF == SparcMCExpr::VK_Sparc_TLS_LDO_HIX22 - || TF == SparcMCExpr::VK_Sparc_TLS_IE_HI22 - || TF == SparcMCExpr::VK_Sparc_TLS_LE_HIX22) && - "Invalid target flags for address operand on sethi"); - else if (Opc == SP::TLS_CALL) - assert((TF == SparcMCExpr::VK_Sparc_None - || TF == SparcMCExpr::VK_Sparc_TLS_GD_CALL - || TF == SparcMCExpr::VK_Sparc_TLS_LDM_CALL) && - "Cannot handle target flags on tls call address"); - else if (Opc == SP::TLS_ADDrr) - assert((TF == SparcMCExpr::VK_Sparc_TLS_GD_ADD - || TF == SparcMCExpr::VK_Sparc_TLS_LDM_ADD - || TF == SparcMCExpr::VK_Sparc_TLS_LDO_ADD - || TF == SparcMCExpr::VK_Sparc_TLS_IE_ADD) && - "Cannot handle target flags on add for TLS"); - else if (Opc == SP::TLS_LDrr) - assert(TF == SparcMCExpr::VK_Sparc_TLS_IE_LD && - "Cannot handle target flags on ld for TLS"); - else if (Opc == SP::TLS_LDXrr) - assert(TF == SparcMCExpr::VK_Sparc_TLS_IE_LDX && - "Cannot handle target flags on ldx for TLS"); - else if (Opc == SP::XORri) - assert((TF == SparcMCExpr::VK_Sparc_TLS_LDO_LOX10 - || TF == SparcMCExpr::VK_Sparc_TLS_LE_LOX10) && - "Cannot handle target flags on xor for TLS"); - else if (Opc != SP::INLINEASM && Opc != SP::INLINEASM_BR) - assert((TF == SparcMCExpr::VK_Sparc_LO - || TF == SparcMCExpr::VK_Sparc_M44 - || TF == SparcMCExpr::VK_Sparc_L44 - || TF == SparcMCExpr::VK_Sparc_HM - || TF == SparcMCExpr::VK_Sparc_TLS_GD_LO10 - || TF == SparcMCExpr::VK_Sparc_TLS_LDM_LO10 - || TF == SparcMCExpr::VK_Sparc_TLS_IE_LO10 ) && - "Invalid target flags for small address operand"); - } -#endif - - bool CloseParen = SparcMCExpr::printVariantKind(O, TF); switch (MO.getType()) { From 2a198c3ae0f3cd8ae953a81d54bc15e30bac6abd Mon Sep 17 00:00:00 2001 From: Koakuma Date: Tue, 20 Aug 2024 12:22:04 +0700 Subject: [PATCH 3/3] Remove stray include --- llvm/lib/Target/Sparc/SparcAsmPrinter.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp b/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp index 8401b42ea189f..71ec01aeb011c 100644 --- a/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp +++ b/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp @@ -31,7 +31,6 @@ #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/TargetRegistry.h" -#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" using namespace llvm;