diff options
| author | Craig Topper <craig.topper@intel.com> | 2018-12-26 21:59:48 +0000 |
|---|---|---|
| committer | Craig Topper <craig.topper@intel.com> | 2018-12-26 21:59:48 +0000 |
| commit | c9a6000755b46ecee5199ae52c89a6b537f1520c (patch) | |
| tree | ff5e9dae4c73fda7b796ad333953031bf2971d87 /llvm/test/Transforms | |
| parent | c168c6f86f811327488b58f7e2cc9826801a0155 (diff) | |
| download | bcm5719-llvm-c9a6000755b46ecee5199ae52c89a6b537f1520c.tar.gz bcm5719-llvm-c9a6000755b46ecee5199ae52c89a6b537f1520c.zip | |
[LoopIdiomRecognize] Add CTTZ support
Summary:
Existing LIR recognizes CTLZ where shifting input variable right until it is zero. (Shift-Until-Zero idiom)
This commit:
1. Augments Shift-Until-Zero idiom to recognize CTTZ where input variable is shifted left.
2. Prepare for BitScan idiom recognition.
Patch by Yuanfang Chen (tabloid.adroit)
Reviewers: craig.topper, evstupac
Reviewed By: craig.topper
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D55876
llvm-svn: 350074
Diffstat (limited to 'llvm/test/Transforms')
| -rw-r--r-- | llvm/test/Transforms/LoopIdiom/X86/cttz.ll | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/llvm/test/Transforms/LoopIdiom/X86/cttz.ll b/llvm/test/Transforms/LoopIdiom/X86/cttz.ll new file mode 100644 index 00000000000..e18fecabe86 --- /dev/null +++ b/llvm/test/Transforms/LoopIdiom/X86/cttz.ll @@ -0,0 +1,82 @@ +; RUN: opt -loop-idiom -mtriple=x86_64 -mcpu=core-avx2 < %s -S | FileCheck --check-prefix=ALL %s +; RUN: opt -loop-idiom -mtriple=x86_64 -mcpu=corei7 < %s -S | FileCheck --check-prefix=ALL %s + +; Recognize CTTZ builtin pattern. +; Here it will replace the loop - +; assume builtin is always profitable. +; +; int cttz_zero_check(int n) +; { +; int i = 0; +; while(n) { +; n <<= 1; +; i++; +; } +; return i; +; } +; +; ALL-LABEL: @cttz_zero_check +; ALL: %0 = call i32 @llvm.cttz.i32(i32 %n, i1 true) +; ALL-NEXT: %1 = sub i32 32, %0 +; +; Function Attrs: norecurse nounwind readnone uwtable +define i32 @cttz_zero_check(i32 %n) { +entry: + %tobool4 = icmp eq i32 %n, 0 + br i1 %tobool4, label %while.end, label %while.body.preheader + +while.body.preheader: ; preds = %entry + br label %while.body + +while.body: ; preds = %while.body.preheader, %while.body + %i.06 = phi i32 [ %inc, %while.body ], [ 0, %while.body.preheader ] + %n.addr.05 = phi i32 [ %shl, %while.body ], [ %n, %while.body.preheader ] + %shl = shl i32 %n.addr.05, 1 + %inc = add nsw i32 %i.06, 1 + %tobool = icmp eq i32 %shl, 0 + br i1 %tobool, label %while.end.loopexit, label %while.body + +while.end.loopexit: ; preds = %while.body + br label %while.end + +while.end: ; preds = %while.end.loopexit, %entry + %i.0.lcssa = phi i32 [ 0, %entry ], [ %inc, %while.end.loopexit ] + ret i32 %i.0.lcssa +} + +; Recognize CTTZ builtin pattern. +; Here it will replace the loop - +; assume builtin is always profitable. +; +; int cttz(int n) +; { +; int i = 0; +; while(n <<= 1) { +; i++; +; } +; return i; +; } +; +; ALL-LABEL: @cttz +; ALL: %0 = shl i32 %n, 1 +; ALL-NEXT: %1 = call i32 @llvm.cttz.i32(i32 %0, i1 false) +; ALL-NEXT: %2 = sub i32 32, %1 +; ALL-NEXT: %3 = add i32 %2, 1 +; +; Function Attrs: norecurse nounwind readnone uwtable +define i32 @cttz(i32 %n) { +entry: + br label %while.cond + +while.cond: ; preds = %while.cond, %entry + %n.addr.0 = phi i32 [ %n, %entry ], [ %shl, %while.cond ] + %i.0 = phi i32 [ 0, %entry ], [ %inc, %while.cond ] + %shl = shl i32 %n.addr.0, 1 + %tobool = icmp eq i32 %shl, 0 + %inc = add nsw i32 %i.0, 1 + br i1 %tobool, label %while.end, label %while.cond + +while.end: ; preds = %while.cond + ret i32 %i.0 +} + |

