[llvm] r304224 - [InstCombine] Add test cases to show missed opportunities to remove compare instructions after cttz/ctlz/ctpop where some bits of the input is known.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue May 30 10:47:59 PDT 2017
Author: ctopper
Date: Tue May 30 12:47:59 2017
New Revision: 304224
URL: http://llvm.org/viewvc/llvm-project?rev=304224&view=rev
Log:
[InstCombine] Add test cases to show missed opportunities to remove compare instructions after cttz/ctlz/ctpop where some bits of the input is known.
Modified:
llvm/trunk/test/Transforms/InstCombine/ctpop.ll
llvm/trunk/test/Transforms/InstCombine/intrinsics.ll
Modified: llvm/trunk/test/Transforms/InstCombine/ctpop.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/ctpop.ll?rev=304224&r1=304223&r2=304224&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/ctpop.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/ctpop.ll Tue May 30 12:47:59 2017
@@ -52,3 +52,19 @@ define i1 @test4(i8 %arg) {
%res = icmp eq i8 %cnt, 2
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.
+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]]
+;
+ %and = and i32 %arg, 3
+ %cnt = call i32 @llvm.ctpop.i32(i32 %and)
+ %res = icmp eq i32 %cnt, 3
+ ret i1 %res
+}
Modified: llvm/trunk/test/Transforms/InstCombine/intrinsics.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/intrinsics.ll?rev=304224&r1=304223&r2=304224&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/intrinsics.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/intrinsics.ll Tue May 30 12:47:59 2017
@@ -305,6 +305,20 @@ define i1 @cttz_knownbits2(i32 %arg) {
ret i1 %res
}
+; TODO: The icmp is unnecessary given the known bits of the input.
+define i1 @cttz_knownbits3(i32 %arg) {
+; CHECK-LABEL: @cttz_knownbits3(
+; CHECK-NEXT: [[OR:%.*]] = or i32 [[ARG:%.*]], 4
+; CHECK-NEXT: [[CNT:%.*]] = call i32 @llvm.cttz.i32(i32 [[OR]], i1 true) #2
+; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[CNT]], 3
+; CHECK-NEXT: ret i1 [[RES]]
+;
+ %or = or i32 %arg, 4
+ %cnt = call i32 @llvm.cttz.i32(i32 %or, i1 true) nounwind readnone
+ %res = icmp eq i32 %cnt, 3
+ ret i1 %res
+}
+
define i8 @ctlz(i8 %a) {
; CHECK-LABEL: @ctlz(
; CHECK-NEXT: ret i8 2
@@ -338,6 +352,20 @@ define i1 @ctlz_knownbits2(i8 %arg) {
ret i1 %res
}
+; TODO: The icmp is unnecessary given the known bits of the input.
+define i1 @ctlz_knownbits3(i8 %arg) {
+; CHECK-LABEL: @ctlz_knownbits3(
+; CHECK-NEXT: [[OR:%.*]] = or i8 [[ARG:%.*]], 32
+; CHECK-NEXT: [[CNT:%.*]] = call i8 @llvm.ctlz.i8(i8 [[OR]], i1 true) #2
+; CHECK-NEXT: [[RES:%.*]] = icmp eq i8 [[CNT]], 3
+; CHECK-NEXT: ret i1 [[RES]]
+;
+ %or = or i8 %arg, 32
+ %cnt = call i8 @llvm.ctlz.i8(i8 %or, i1 true) nounwind readnone
+ %res = icmp eq i8 %cnt, 3
+ ret i1 %res
+}
+
define void @cmp.simplify(i32 %a, i32 %b, i1* %c) {
%lz = tail call i32 @llvm.ctlz.i32(i32 %a, i1 false) nounwind readnone
%lz.cmp = icmp eq i32 %lz, 32
More information about the llvm-commits
mailing list