[llvm] 83d690a - Don't rely on 'l'(ell) modifiers to indicate a label reference

Bill Wendling via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 6 14:44:48 PST 2020


Author: Bill Wendling
Date: 2020-01-06T14:44:03-08:00
New Revision: 83d690a149802d40c711d4fb5a058dd1ebe4aa23

URL: https://github.com/llvm/llvm-project/commit/83d690a149802d40c711d4fb5a058dd1ebe4aa23
DIFF: https://github.com/llvm/llvm-project/commit/83d690a149802d40c711d4fb5a058dd1ebe4aa23.diff

LOG: Don't rely on 'l'(ell) modifiers to indicate a label reference

Summary:
It's not necessary to use an 'l'(ell) modifier when referencing a label.
Treat block addresses and MBB references as if the modifier is used
anyway. This prevents us from generating references to ficticious
labels.

Reviewers: jyknight, nickdesaulniers, hfinkel

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D71849

Added: 
    

Modified: 
    llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
    llvm/test/CodeGen/X86/callbr-asm.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
index a0179539533e..c631cc5360b8 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -456,26 +456,23 @@ static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
 
           // FIXME: Shouldn't arch-independent output template handling go into
           // PrintAsmOperand?
-          if (Modifier[0] == 'l') { // Labels are target independent.
-            if (MI->getOperand(OpNo).isBlockAddress()) {
-              const BlockAddress *BA = MI->getOperand(OpNo).getBlockAddress();
-              MCSymbol *Sym = AP->GetBlockAddressSymbol(BA);
-              Sym->print(OS, AP->MAI);
-              MMI->getContext().registerInlineAsmLabel(Sym);
-            } else if (MI->getOperand(OpNo).isMBB()) {
-              const MCSymbol *Sym = MI->getOperand(OpNo).getMBB()->getSymbol();
-              Sym->print(OS, AP->MAI);
-            } else {
-              Error = true;
-            }
+          // Labels are target independent.
+          if (MI->getOperand(OpNo).isBlockAddress()) {
+            const BlockAddress *BA = MI->getOperand(OpNo).getBlockAddress();
+            MCSymbol *Sym = AP->GetBlockAddressSymbol(BA);
+            Sym->print(OS, AP->MAI);
+            MMI->getContext().registerInlineAsmLabel(Sym);
+          } else if (MI->getOperand(OpNo).isMBB()) {
+            const MCSymbol *Sym = MI->getOperand(OpNo).getMBB()->getSymbol();
+            Sym->print(OS, AP->MAI);
+          } else if (Modifier[0] == 'l') {
+            Error = true;
+          } else if (InlineAsm::isMemKind(OpFlags)) {
+            Error = AP->PrintAsmMemoryOperand(
+                MI, OpNo, Modifier[0] ? Modifier : nullptr, OS);
           } else {
-            if (InlineAsm::isMemKind(OpFlags)) {
-              Error = AP->PrintAsmMemoryOperand(
-                  MI, OpNo, Modifier[0] ? Modifier : nullptr, OS);
-            } else {
-              Error = AP->PrintAsmOperand(MI, OpNo,
-                                          Modifier[0] ? Modifier : nullptr, OS);
-            }
+            Error = AP->PrintAsmOperand(MI, OpNo,
+                                        Modifier[0] ? Modifier : nullptr, OS);
           }
         }
         if (Error) {

diff  --git a/llvm/test/CodeGen/X86/callbr-asm.ll b/llvm/test/CodeGen/X86/callbr-asm.ll
index ed3c314ed424..8938aefca087 100644
--- a/llvm/test/CodeGen/X86/callbr-asm.ll
+++ b/llvm/test/CodeGen/X86/callbr-asm.ll
@@ -53,7 +53,6 @@ fail:
   ret i32 1
 }
 
-
 ; Test 3 - asm-goto implements a loop. The loop gets recognized, but many loop
 ; transforms fail due to canonicalization having callbr exceptions. Trivial
 ; blocks at labels 1 and 3 also don't get simplified due to callbr.
@@ -131,3 +130,32 @@ normal1:                                          ; preds = %normal0
   %1 = load i32, i32* %a.addr, align 4
   ret i32 %1
 }
+
+; Test 4 - asm-goto referenced with the 'l' (ell) modifier and not.
+define void @test4() {
+; CHECK-LABEL: test4:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    #APP
+; CHECK-NOT:     ja .Ltmp50
+; CHECK-NEXT:    ja .Ltmp5
+; CHECK-NEXT:    #NO_APP
+; CHECK-NEXT:  .LBB3_1:
+; CHECK-NEXT:    #APP
+; CHECK-NOT:     ja .Ltmp50
+; CHECK-NEXT:    ja .Ltmp5
+; CHECK-NEXT:    #NO_APP
+; CHECK-NEXT:    jmp .LBB3_3
+entry:
+  callbr void asm sideeffect "ja $0", "X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@test4, %quux))
+          to label %asm.fallthrough [label %quux]
+
+asm.fallthrough:                                  ; preds = %entry
+  callbr void asm sideeffect "ja ${0:l}", "X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@test4, %quux))
+          to label %cleanup [label %quux]
+
+quux:                                             ; preds = %asm.fallthrough, %entry
+  br label %cleanup
+
+cleanup:                                          ; preds = %asm.fallthrough, %quux
+  ret void
+}


        


More information about the llvm-commits mailing list