summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/SimplifyCFG/multiple-phis.ll
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2012-01-05 23:58:56 +0000
committerDan Gohman <gohman@apple.com>2012-01-05 23:58:56 +0000
commit5ab9c0a9270d34b8f7b2eee600b47a62dadf82c0 (patch)
treecb82d72a9e8d1086a42a7d6b466c441e130cb9b5 /llvm/test/Transforms/SimplifyCFG/multiple-phis.ll
parent3e8cd274e8a180f2c34fa6a672b982211ef05a31 (diff)
downloadbcm5719-llvm-5ab9c0a9270d34b8f7b2eee600b47a62dadf82c0.tar.gz
bcm5719-llvm-5ab9c0a9270d34b8f7b2eee600b47a62dadf82c0.zip
Fix SpeculativelyExecuteBB to either speculate all or none of the phis
present in the bottom of the CFG triangle, as the transformation isn't ever valuable if the branch can't be eliminated. Also, unify some heuristics between SimplifyCFG's multiple if-converters, for consistency. This fixes rdar://10627242. llvm-svn: 147630
Diffstat (limited to 'llvm/test/Transforms/SimplifyCFG/multiple-phis.ll')
-rw-r--r--llvm/test/Transforms/SimplifyCFG/multiple-phis.ll39
1 files changed, 39 insertions, 0 deletions
diff --git a/llvm/test/Transforms/SimplifyCFG/multiple-phis.ll b/llvm/test/Transforms/SimplifyCFG/multiple-phis.ll
new file mode 100644
index 00000000000..78454232461
--- /dev/null
+++ b/llvm/test/Transforms/SimplifyCFG/multiple-phis.ll
@@ -0,0 +1,39 @@
+; RUN: opt -simplifycfg -S < %s | FileCheck %s
+
+; It's not worthwhile to if-convert one of the phi nodes and leave
+; the other behind, because that still requires a branch. If
+; SimplifyCFG if-converts one of the phis, it should do both.
+
+; CHECK: %div.high.addr.0 = select i1 %cmp1, i32 %div, i32 %high.addr.0
+; CHECK-NEXT: %low.0.add2 = select i1 %cmp1, i32 %low.0, i32 %add2
+; CHECK-NEXT: br label %while.cond
+
+define i32 @upper_bound(i32* %r, i32 %high, i32 %k) nounwind {
+entry:
+ br label %while.cond
+
+while.cond: ; preds = %if.then, %if.else, %entry
+ %high.addr.0 = phi i32 [ %high, %entry ], [ %div, %if.then ], [ %high.addr.0, %if.else ]
+ %low.0 = phi i32 [ 0, %entry ], [ %low.0, %if.then ], [ %add2, %if.else ]
+ %cmp = icmp ult i32 %low.0, %high.addr.0
+ br i1 %cmp, label %while.body, label %while.end
+
+while.body: ; preds = %while.cond
+ %add = add i32 %low.0, %high.addr.0
+ %div = udiv i32 %add, 2
+ %idxprom = zext i32 %div to i64
+ %arrayidx = getelementptr inbounds i32* %r, i64 %idxprom
+ %0 = load i32* %arrayidx
+ %cmp1 = icmp ult i32 %k, %0
+ br i1 %cmp1, label %if.then, label %if.else
+
+if.then: ; preds = %while.body
+ br label %while.cond
+
+if.else: ; preds = %while.body
+ %add2 = add i32 %div, 1
+ br label %while.cond
+
+while.end: ; preds = %while.cond
+ ret i32 %low.0
+}
OpenPOWER on IntegriCloud