diff options
Diffstat (limited to 'test/Transforms/InstCombine/ctpop.ll')
-rw-r--r-- | test/Transforms/InstCombine/ctpop.ll | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/test/Transforms/InstCombine/ctpop.ll b/test/Transforms/InstCombine/ctpop.ll index d49a907ffce1d..e8e3603e4cb8a 100644 --- a/test/Transforms/InstCombine/ctpop.ll +++ b/test/Transforms/InstCombine/ctpop.ll @@ -3,6 +3,8 @@ declare i32 @llvm.ctpop.i32(i32) declare i8 @llvm.ctpop.i8(i8) +declare i1 @llvm.ctpop.i1(i1) +declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32>) declare void @llvm.assume(i1) define i1 @test1(i32 %arg) { @@ -44,7 +46,7 @@ define i1 @test3(i32 %arg) { ; Negative test for when we know nothing define i1 @test4(i8 %arg) { ; CHECK-LABEL: @test4( -; CHECK-NEXT: [[CNT:%.*]] = call i8 @llvm.ctpop.i8(i8 [[ARG:%.*]]) +; CHECK-NEXT: [[CNT:%.*]] = call i8 @llvm.ctpop.i8(i8 [[ARG:%.*]]), !range ![[RANGE:[0-9]+]] ; CHECK-NEXT: [[RES:%.*]] = icmp eq i8 [[CNT]], 2 ; CHECK-NEXT: ret i1 [[RES]] ; @@ -55,16 +57,41 @@ define i1 @test4(i8 %arg) { ; Test when the number of possible known bits isn't one less than a power of 2 ; and the compare value is greater but less than the next power of 2. -; TODO: The icmp is unnecessary given the known bits of the input. define i1 @test5(i32 %arg) { ; CHECK-LABEL: @test5( -; CHECK-NEXT: [[AND:%.*]] = and i32 [[ARG:%.*]], 3 -; CHECK-NEXT: [[CNT:%.*]] = call i32 @llvm.ctpop.i32(i32 [[AND]]) -; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[CNT]], 3 -; CHECK-NEXT: ret i1 [[RES]] +; CHECK-NEXT: ret i1 false ; %and = and i32 %arg, 3 %cnt = call i32 @llvm.ctpop.i32(i32 %and) %res = icmp eq i32 %cnt, 3 ret i1 %res } + +; Test when the number of possible known bits isn't one less than a power of 2 +; and the compare value is greater but less than the next power of 2. +; TODO: The icmp is unnecessary given the known bits of the input, but range +; metadata doesn't support vectors +define <2 x i1> @test5vec(<2 x i32> %arg) { +; CHECK-LABEL: @test5vec( +; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[ARG:%.*]], <i32 3, i32 3> +; CHECK-NEXT: [[CNT:%.*]] = call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> [[AND]]) +; CHECK-NEXT: [[RES:%.*]] = icmp eq <2 x i32> [[CNT]], <i32 3, i32 3> +; CHECK-NEXT: ret <2 x i1> [[RES]] +; + %and = and <2 x i32> %arg, <i32 3, i32 3> + %cnt = call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %and) + %res = icmp eq <2 x i32> %cnt, <i32 3, i32 3> + ret <2 x i1> %res +} + +; Make sure we don't add range metadata to i1 ctpop. +define i1 @test6(i1 %arg) { +; CHECK-LABEL: @test6( +; CHECK-NEXT: [[CNT:%.*]] = call i1 @llvm.ctpop.i1(i1 [[ARG:%.*]]) +; CHECK-NEXT: ret i1 [[CNT]] +; + %cnt = call i1 @llvm.ctpop.i1(i1 %arg) + ret i1 %cnt +} + +; CHECK: ![[RANGE]] = !{i8 0, i8 9} |