[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 11:27:50 PDT 2018
vchuravy created this revision.
vchuravy added reviewers: kparzysz, iteratee.
Herald added a subscriber: nemanjai.
While I was updating the Julia frontend for LLVM 6.0.0 I encountered a situation
where we emitted code that triggered the diamond conversion in if-converter while
TrueBB and FalseBB terminated in `ret`.
BB
/ \
TrueBB FalseBB
... ...
ret ret
The if-converter pass decided that this was a valid structure to do a diamond conversion on
and this triggered an assertion later on since if-converter implictly assumed that TrueBB and
FalseBB terminate in a branch or a fall-trough. Since the situation described above is equivalent
to:
BB
/ \
TrueBB FalseBB
... ...
\ /
BB
ret
I think it reasonable for if-converter to do a diamond conversion on and so this PR adds a bit handling for
return (treating returns as a form of an unconditional branch).
This fixes https://bugs.llvm.org/show_bug.cgi?id=36825
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,36 @@
+# 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 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: BCLRn $cr2lt, implicit $lr8, implicit $rm, implicit $x3
+# CHECK: BCLR $cr2lt, implicit $lr8, implicit $rm, implicit $x3
+
+
Index: lib/CodeGen/IfConversion.cpp
===================================================================
--- lib/CodeGen/IfConversion.cpp
+++ lib/CodeGen/IfConversion.cpp
@@ -646,7 +646,8 @@
if (TII->DefinesPredicate(*TIB, PredDefs))
return false;
// If we get all the way to the branch instructions, don't count them.
- if (!TIB->isBranch())
+ // We treat returns as unconditional branches
+ if (!(TIB->isBranch() || TIB->isReturn()))
++Dups1;
++TIB;
++FIB;
@@ -685,7 +686,7 @@
break;
// We have to verify that any branch instructions are the same, and then we
// don't count them toward the # of duplicate instructions.
- if (!RTIE->isBranch())
+ if (!(RTIE->isBranch() || RTIE->isReturn()))
++Dups2;
++RTIE;
++RFIE;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45218.140835.patch
Type: text/x-patch
Size: 2166 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180403/1ff7d4bf/attachment.bin>
More information about the llvm-commits
mailing list