[PATCH] D28780: [ValueTracking] Extend known bits to understand @llvm.bitreverse.
Chad Rosier via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 17 09:34:53 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL292233: [ValueTracking] Extend known bits to understand @llvm.bitreverse. (authored by mcrosier).
Changed prior to commit:
https://reviews.llvm.org/D28780?vs=84596&id=84688#toc
Repository:
rL LLVM
https://reviews.llvm.org/D28780
Files:
llvm/trunk/lib/Analysis/ValueTracking.cpp
llvm/trunk/test/Transforms/InstCombine/bitreverse-known-bits.ll
llvm/trunk/test/Transforms/InstSimplify/bitreverse.ll
Index: llvm/trunk/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp
@@ -1400,6 +1400,11 @@
if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
switch (II->getIntrinsicID()) {
default: break;
+ case Intrinsic::bitreverse:
+ computeKnownBits(I->getOperand(0), KnownZero2, KnownOne2, Depth + 1, Q);
+ KnownZero = KnownZero2.reverseBits();
+ KnownOne = KnownOne2.reverseBits();
+ break;
case Intrinsic::bswap:
computeKnownBits(I->getOperand(0), KnownZero2, KnownOne2, Depth + 1, Q);
KnownZero |= KnownZero2.byteSwap();
Index: llvm/trunk/test/Transforms/InstCombine/bitreverse-known-bits.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/bitreverse-known-bits.ll
+++ llvm/trunk/test/Transforms/InstCombine/bitreverse-known-bits.ll
@@ -0,0 +1,34 @@
+; RUN: opt < %s -S -instcombine | FileCheck %s
+
+declare i32 @llvm.bitreverse.i32(i32)
+
+; CHECK-LABEL: @test1
+; CHECK: ret i1 true
+define i1 @test1(i32 %arg) {
+ %a = or i32 %arg, 4294901760
+ %b = call i32 @llvm.bitreverse.i32(i32 %a)
+ %and = and i32 %b, 65535
+ %res = icmp eq i32 %and, 65535
+ ret i1 %res
+}
+
+; CHECK-LABEL: @test2
+; CHECK: ret i1 true
+define i1 @test2(i32 %arg) {
+ %a = or i32 %arg, 1
+ %b = call i32 @llvm.bitreverse.i32(i32 %a)
+ %c = and i32 %b, 2147483648
+ %d = call i32 @llvm.bitreverse.i32(i32 %c)
+ %res = icmp eq i32 %d, 1
+ ret i1 %res
+}
+
+; CHECK-LABEL: @test3
+; CHECK: ret i1 false
+define i1 @test3(i32 %arg) {
+ %a = or i32 %arg, 65536
+ %b = call i32 @llvm.bitreverse.i32(i32 %a)
+ %and = and i32 %b, 32768
+ %res = icmp eq i32 %and, 0
+ ret i1 %res
+}
Index: llvm/trunk/test/Transforms/InstSimplify/bitreverse.ll
===================================================================
--- llvm/trunk/test/Transforms/InstSimplify/bitreverse.ll
+++ llvm/trunk/test/Transforms/InstSimplify/bitreverse.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -S -instsimplify | FileCheck %s
+
+declare i32 @llvm.bitreverse.i32(i32)
+
+; CHECK-LABEL: @test1(
+; CHECK: ret i1 false
+define i1 @test1(i32 %arg) {
+ %a = or i32 %arg, 1
+ %b = call i32 @llvm.bitreverse.i32(i32 %a)
+ %res = icmp eq i32 %b, 0
+ ret i1 %res
+}
+
+; CHECK-LABEL: @test2(
+; CHECK: ret i1 false
+define i1 @test2(i32 %arg) {
+ %a = or i32 %arg, 1024
+ %b = call i32 @llvm.bitreverse.i32(i32 %a)
+ %res = icmp eq i32 %b, 0
+ ret i1 %res
+}
+
+; CHECK-LABEL: @test3(
+; CHECK: ret i1 false
+define i1 @test3(i32 %arg) {
+ %a = and i32 %arg, 1
+ %b = call i32 @llvm.bitreverse.i32(i32 %a)
+ %and = and i32 %b, 1
+ %res = icmp eq i32 %and, 1
+ ret i1 %res
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28780.84688.patch
Type: text/x-patch
Size: 2817 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170117/948f0d7f/attachment.bin>
More information about the llvm-commits
mailing list