llvm.org GIT mirror llvm / 8b2dfae
Extend known bits to understand @llvm.bswap This is a cleaned up patch from the one written by John Regehr based on the findings of the Souper superoptimizer. When writing tests, I was surprised to find that instsimplify apparently doesn't know how to collapse bit test sequences based purely on known bits. This required me to split my tests across both instsimplify and instcombine. Differential Revision: http://reviews.llvm.org/D13250 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249453 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 4 years ago
3 changed file(s) with 94 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
13571357 if (IntrinsicInst *II = dyn_cast(I)) {
13581358 switch (II->getIntrinsicID()) {
13591359 default: break;
1360 case Intrinsic::bswap:
1361 computeKnownBits(I->getOperand(0), KnownZero2, KnownOne2, DL,
1362 Depth + 1, Q);
1363 KnownZero |= KnownZero2.byteSwap();
1364 KnownOne |= KnownOne2.byteSwap();
1365 break;
13601366 case Intrinsic::ctlz:
13611367 case Intrinsic::cttz: {
13621368 unsigned LowBits = Log2_32(BitWidth)+1;
0 ; RUN: opt < %s -S -instcombine | FileCheck %s
1 ; Note: This is testing functionality in computeKnownBits. I'd have rather
2 ; used instsimplify, but the bit test folding is apparently only in instcombine.
3
4 declare i16 @llvm.bswap.i16(i16)
5 declare i32 @llvm.bswap.i32(i32)
6
7 define i1 @test1(i16 %arg) {
8 ; CHECK-LABEL: @test1
9 ; CHECK: ret i1 true
10 %a = or i16 %arg, 511
11 %b = call i16 @llvm.bswap.i16(i16 %a)
12 %and = and i16 %b, 256
13 %res = icmp eq i16 %and, 256
14 ret i1 %res
15 }
16
17 define i1 @test2(i16 %arg) {
18 ; CHECK-LABEL: @test2
19 ; CHECK: ret i1 true
20 %a = or i16 %arg, 1
21 %b = call i16 @llvm.bswap.i16(i16 %a)
22 %and = and i16 %b, 256
23 %res = icmp eq i16 %and, 256
24 ret i1 %res
25 }
26
27
28 define i1 @test3(i16 %arg) {
29 ; CHECK-LABEL: @test3
30 ; CHECK: ret i1 true
31 %a = or i16 %arg, 256
32 %b = call i16 @llvm.bswap.i16(i16 %a)
33 %and = and i16 %b, 1
34 %res = icmp eq i16 %and, 1
35 ret i1 %res
36 }
37
38 define i1 @test4(i32 %arg) {
39 ; CHECK-LABEL: @test4
40 ; CHECK: ret i1 true
41 %a = or i32 %arg, 2147483647 ; i32_MAX
42 %b = call i32 @llvm.bswap.i32(i32 %a)
43 %and = and i32 %b, 127
44 %res = icmp eq i32 %and, 127
45 ret i1 %res
46 }
0 ; RUN: opt < %s -S -instsimplify | FileCheck %s
1
2 declare i16 @llvm.bswap.i16(i16)
3
4 define i1 @test1(i16 %arg) {
5 ; CHECK-LABEL: @test1
6 ; CHECK: ret i1 false
7 %a = or i16 %arg, 1
8 %b = call i16 @llvm.bswap.i16(i16 %a)
9 %res = icmp eq i16 %b, 0
10 ret i1 %res
11 }
12
13 define i1 @test2(i16 %arg) {
14 ; CHECK-LABEL: @test2
15 ; CHECK: ret i1 false
16 %a = or i16 %arg, 1024
17 %b = call i16 @llvm.bswap.i16(i16 %a)
18 %res = icmp eq i16 %b, 0
19 ret i1 %res
20 }
21
22 define i1 @test3(i16 %arg) {
23 ; CHECK-LABEL: @test3
24 ; CHECK: ret i1 false
25 %a = and i16 %arg, 1
26 %b = call i16 @llvm.bswap.i16(i16 %a)
27 %and = and i16 %b, 1
28 %res = icmp eq i16 %and, 1
29 ret i1 %res
30 }
31
32 define i1 @test4(i16 %arg) {
33 ; CHECK-LABEL: @test4
34 ; CHECK: ret i1 false
35 %a = and i16 %arg, 511
36 %b = call i16 @llvm.bswap.i16(i16 %a)
37 %and = and i16 %b, 256
38 %res = icmp eq i16 %and, 1
39 ret i1 %res
40 }