summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2018-07-11 22:17:26 +0000
committerCraig Topper <craig.topper@intel.com>2018-07-11 22:17:26 +0000
commitef08aec9352a4827a2f9c83fffd7844155b1a633 (patch)
tree6606b92ae2a6d0bb7b94ee1a5455c0bae711d4c3 /llvm/test/Transforms
parent752ddbd0684a5173071ed22a7fa289a09e72d020 (diff)
downloadbcm5719-llvm-ef08aec9352a4827a2f9c83fffd7844155b1a633.tar.gz
bcm5719-llvm-ef08aec9352a4827a2f9c83fffd7844155b1a633.zip
[LoopIdiomRecognize] Add a test case showing a loop we turn into ctlz that we shouldn't.
This loop executes one iteration without checking the input value. This produces a count of 1 for an input of 0 and 1. We are turning this into 32 - ctlz(n), but that returns 0 if n is 0. llvm-svn: 336862
Diffstat (limited to 'llvm/test/Transforms')
-rw-r--r--llvm/test/Transforms/LoopIdiom/X86/ctlz.ll36
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/test/Transforms/LoopIdiom/X86/ctlz.ll b/llvm/test/Transforms/LoopIdiom/X86/ctlz.ll
index e1e6998f64c..b863856f206 100644
--- a/llvm/test/Transforms/LoopIdiom/X86/ctlz.ll
+++ b/llvm/test/Transforms/LoopIdiom/X86/ctlz.ll
@@ -483,3 +483,39 @@ while.end: ; preds = %while.cond.while.en
ret i32 %cnt.0.lcssa
}
+; FIXME: We should not transform this loop. It returns 1 for an input of both
+; 0 and 1.
+;
+; int ctlz_bad(unsigned n)
+; {
+; int i = 0;
+; do {
+; i++;
+; n >>= 1;
+; } while(n != 0) {
+; return i;
+; }
+;
+; ALL: entry
+; ALL-NEXT: %0 = call i32 @llvm.ctlz.i32(i32 %n, i1 false)
+; ALL-NEXT: %1 = sub i32 32, %0
+; ALL-NEXT: br label %while.cond
+; ALL: %inc.lcssa = phi i32 [ %1, %while.cond ]
+; ALL: ret i32 %inc.lcssa
+
+; Function Attrs: norecurse nounwind readnone uwtable
+define i32 @ctlz_bad(i32 %n) {
+entry:
+ br label %while.cond
+
+while.cond: ; preds = %while.cond, %entry
+ %n.addr.0 = phi i32 [ %n, %entry ], [ %shr, %while.cond ]
+ %i.0 = phi i32 [ 0, %entry ], [ %inc, %while.cond ]
+ %shr = lshr i32 %n.addr.0, 1
+ %tobool = icmp eq i32 %shr, 0
+ %inc = add nsw i32 %i.0, 1
+ br i1 %tobool, label %while.end, label %while.cond
+
+while.end: ; preds = %while.cond
+ ret i32 %inc
+}
OpenPOWER on IntegriCloud