[PATCH] D45218: [if-converter] Handle BB that terminate in ret during diamond conversion

Valentin Churavy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 3 21:30:34 PDT 2018


vchuravy updated this revision to Diff 140901.
vchuravy added a comment.

@nemanjai correctly noted that the both branches are equal and we can simplify this,
by making sure that we don't fall over the iterator and then removing both BB.

My previous version causes problems for other test cases and this version passes my minimal test 
and the case found in the Julia frontend.


Repository:
  rL LLVM

https://reviews.llvm.org/D45218

Files:
  lib/CodeGen/IfConversion.cpp
  test/CodeGen/MIR/PowerPC/ifcvt-diamond-ret.mir


Index: test/CodeGen/MIR/PowerPC/ifcvt-diamond-ret.mir
===================================================================
--- /dev/null
+++ test/CodeGen/MIR/PowerPC/ifcvt-diamond-ret.mir
@@ -0,0 +1,34 @@
+# RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -run-pass=if-converter %s -o - | FileCheck %s
+---
+name:           foo
+body:           |
+  bb.0:
+  liveins: $x0, $x3
+  successors: %bb.1(0x40000000), %bb.2(0x40000000)
+
+  dead renamable $x3 = ANDIo8 killed renamable $x3, 1, implicit-def dead $cr0, implicit-def $cr0gt
+  $cr2lt = CROR $cr0gt, $cr0gt
+  BCn killed renamable $cr2lt, %bb.2
+  B %bb.1
+
+  bb.1:
+    renamable $x3 = LIS8 4096
+    MTLR8 $x0, implicit-def $lr8
+    BLR8 implicit $lr8, implicit $rm, implicit $x3
+
+  bb.2:
+    renamable $x3 = LIS8 4096
+    MTLR8 $x0, implicit-def $lr8
+    BLR8 implicit $lr8, implicit $rm, implicit $x3
+...
+
+# Diamond testcase with equivalent branches terminating in returns.
+
+# CHECK: body:             |          
+# CHECK:  bb.0:
+# CHECK:    dead renamable $x3 = ANDIo8 killed renamable $x3, 1, implicit-def dead $cr0, implicit-def $cr0gt
+# CHECK:    $cr2lt = CROR $cr0gt, $cr0gt
+# CHECK:    renamable $x3 = LIS8 4096
+# CHECK:    MTLR8 $x0, implicit-def $lr8
+# CHECK:    BLR8 implicit $lr8, implicit $rm, implicit $x3
+
Index: lib/CodeGen/IfConversion.cpp
===================================================================
--- lib/CodeGen/IfConversion.cpp
+++ lib/CodeGen/IfConversion.cpp
@@ -1723,11 +1723,15 @@
   // Skip past the dups on each side separately since there may be
   // differing dbg_value entries.
   for (unsigned i = 0; i < NumDups1; ++DI1) {
+    if (DI1 == MBB1.end())
+      break;
     if (!DI1->isDebugValue())
       ++i;
   }
   while (NumDups1 != 0) {
     ++DI2;
+    if (DI2 == MBB2.end())
+      break;
     if (!DI2->isDebugValue())
       --NumDups1;
   }
@@ -1762,6 +1766,12 @@
   }
   MBB1.erase(DI1, MBB1.end());
 
+  // Identical blocks, already moved all the instructions up.
+  if (MBB1.empty() && MBB2.empty()) {
+    BBI.BB->removeSuccessor(&MBB1, true);
+    BBI.BB->removeSuccessor(&MBB2, true);
+    return true;
+  }
   DI2 = BBI2->BB->end();
   // The branches have been checked to match. Skip over the branch in the false
   // block so that we don't try to predicate it.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45218.140901.patch
Type: text/x-patch
Size: 2297 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180404/f982f8a4/attachment.bin>


More information about the llvm-commits mailing list