[PATCH] D62555: [TailDuplicator] prevent tail duplication for INLINEASM_BR

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 31 11:05:19 PDT 2019


nickdesaulniers updated this revision to Diff 202464.
nickdesaulniers added a comment.

- add fixme


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62555/new/

https://reviews.llvm.org/D62555

Files:
  llvm/lib/CodeGen/TailDuplicator.cpp
  llvm/test/CodeGen/ARM/ifcvt-inline-asm.ll


Index: llvm/test/CodeGen/ARM/ifcvt-inline-asm.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/ARM/ifcvt-inline-asm.ll
@@ -0,0 +1,55 @@
+; RUN: llc -mtriple=arm-linux-gnueabi -print-machineinstrs=tailduplication %s \
+; RUN:   -o /dev/null 2>&1 | FileCheck --check-prefixes=CHECK-TAILDUP %s
+
+; RUN: llc -mtriple=arm-linux-gnueabi -print-machineinstrs=if-converter %s \
+; RUN:   -o /dev/null 2>&1 | FileCheck --check-prefixes=CHECK-IFCVT %s
+
+; Check that INLINEASM_BR did not get duplicated into the previously duplicated
+; blocks by Tail Duplication.
+
+; CHECK-TAILDUP: bb.2.if.else:
+; CHECK-TAILDUP: INLINEASM &"str $1, $0" [sideeffect] [mayload] [attdialect], $0:[mem:Q], killed renamable $r0, $1:[reguse:GPR], killed renamable $r1
+; CHECK-TAILDUP: bb.3.if.end:
+; CHECK-TAILDUP: INLINEASM_BR &"" [sideeffect] [attdialect], $0:[imm], blockaddress(@f, %ir-block.g)
+
+; Check that INLINEASM_BR was merged back into one block successfully by If Convert.
+; CHECK-IFCVT: bb.0.entry:
+; CHECK-IFCVT:   INLINEASM &"str $1, $0" [sideeffect] [mayload] [attdialect], $0:[mem:Q], killed renamable $r0, $1:[reguse:GPR], killed renamable $r1
+; CHECK-IFCVT:   INLINEASM_BR &"" [sideeffect] [attdialect], $0:[imm], blockaddress(@f, %ir-block.g)
+; CHECK-IFCVT: bb.1.asm.fallthrough:
+; CHECK-IFCVT: bb.2.g (address-taken):
+
+; Test case is a c-reduced then bugpointed sound/soc/ti/davinci-i2s.c from the
+; Linux kernel.
+
+ at a = external dso_local local_unnamed_addr global i32*, align 4
+ at c = external dso_local local_unnamed_addr global i32, align 4
+
+define dso_local i32 @f() #0 {
+entry:
+  %0 = load i32, i32* @c, align 4
+  %tobool = icmp eq i32 %0, 0
+  %1 = load i32*, i32** @a, align 4
+  br i1 %tobool, label %if.else, label %if.then
+
+if.then:                                          ; preds = %entry
+  tail call void asm sideeffect "str $1, $0", "*Qo,r"(i32* %1, i32 1) #1
+  br label %if.end
+
+if.else:                                          ; preds = %entry
+  tail call void asm sideeffect "str $1, $0", "*Qo,r"(i32* %1, i32 0) #1
+  br label %if.end
+
+if.end:                                           ; preds = %if.else, %if.then
+  callbr void asm sideeffect "", "X"(i8* blockaddress(@f, %g)) #1
+          to label %asm.fallthrough [label %g]
+
+asm.fallthrough:                                  ; preds = %if.end
+  unreachable
+
+g:                                                ; preds = %if.end
+  ret i32 undef
+}
+
+attributes #0 = { "use-soft-float"="false" }
+attributes #1 = { nounwind }
Index: llvm/lib/CodeGen/TailDuplicator.cpp
===================================================================
--- llvm/lib/CodeGen/TailDuplicator.cpp
+++ llvm/lib/CodeGen/TailDuplicator.cpp
@@ -623,6 +623,14 @@
 
     if (InstrCount > MaxDuplicateCount)
       return false;
+
+    // Because INLINEASM_BR cannot be predicated, leave it in its own block. If
+    // Converter still appears to produce optimal code without having to special
+    // case INLINEASM_BR.
+    // FIXME: improve If Conversion to avoid attempting to predicate such
+    // instructions, and fix improper tail merging of these instructions.
+    if (MI.getOpcode() == TargetOpcode::INLINEASM_BR)
+      return false;
   }
 
   // Check if any of the successors of TailBB has a PHI node in which the


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62555.202464.patch
Type: text/x-patch
Size: 3360 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190531/c401ceef/attachment.bin>


More information about the llvm-commits mailing list