[llvm] 701a8b3 - [InstCombine] Add test for ctlz->cttz fold with constant in select (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 14 02:52:24 PDT 2023
Author: Nikita Popov
Date: 2023-07-14T11:52:14+02:00
New Revision: 701a8b348ecd74d991c979343a51171a11d5e3ee
URL: https://github.com/llvm/llvm-project/commit/701a8b348ecd74d991c979343a51171a11d5e3ee
DIFF: https://github.com/llvm/llvm-project/commit/701a8b348ecd74d991c979343a51171a11d5e3ee.diff
LOG: [InstCombine] Add test for ctlz->cttz fold with constant in select (NFC)
Added:
Modified:
llvm/test/Transforms/InstCombine/select-ctlz-to-cttz.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/select-ctlz-to-cttz.ll b/llvm/test/Transforms/InstCombine/select-ctlz-to-cttz.ll
index 7b7e7c7960c1c1..7bd6a20c31bb5d 100644
--- a/llvm/test/Transforms/InstCombine/select-ctlz-to-cttz.ll
+++ b/llvm/test/Transforms/InstCombine/select-ctlz-to-cttz.ll
@@ -42,6 +42,25 @@ define i32 @select_clz_to_ctz_preserve_flag(i32 %a) {
ret i32 %cond
}
+define i32 @select_clz_to_ctz_constant_for_zero(i32 %a) {
+; CHECK-LABEL: @select_clz_to_ctz_constant_for_zero(
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[A:%.*]]
+; CHECK-NEXT: [[AND:%.*]] = and i32 [[SUB]], [[A]]
+; CHECK-NEXT: [[LZ:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[AND]], i1 false), !range [[RNG0]]
+; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A]], 0
+; CHECK-NEXT: [[SUB1:%.*]] = xor i32 [[LZ]], 31
+; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 32, i32 [[SUB1]]
+; CHECK-NEXT: ret i32 [[COND]]
+;
+ %sub = sub i32 0, %a
+ %and = and i32 %sub, %a
+ %lz = tail call i32 @llvm.ctlz.i32(i32 %and, i1 false)
+ %tobool = icmp eq i32 %a, 0
+ %sub1 = xor i32 %lz, 31
+ %cond = select i1 %tobool, i32 32, i32 %sub1
+ ret i32 %cond
+}
+
define <2 x i32> @select_clz_to_ctz_vec(<2 x i32> %a) {
; CHECK-LABEL: @select_clz_to_ctz_vec(
; CHECK-NEXT: [[COND:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[A:%.*]], i1 true), !range [[RNG0]]
@@ -218,6 +237,25 @@ define <2 x i32> @select_clz_to_ctz_vec_with_undef(<2 x i32> %a) {
ret <2 x i32> %cond
}
+define i32 @select_clz_to_ctz_wrong_constant_for_zero(i32 %a) {
+; CHECK-LABEL: @select_clz_to_ctz_wrong_constant_for_zero(
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[A:%.*]]
+; CHECK-NEXT: [[AND:%.*]] = and i32 [[SUB]], [[A]]
+; CHECK-NEXT: [[LZ:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[AND]], i1 false), !range [[RNG0]]
+; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A]], 0
+; CHECK-NEXT: [[SUB1:%.*]] = xor i32 [[LZ]], 31
+; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 31, i32 [[SUB1]]
+; CHECK-NEXT: ret i32 [[COND]]
+;
+ %sub = sub i32 0, %a
+ %and = and i32 %sub, %a
+ %lz = tail call i32 @llvm.ctlz.i32(i32 %and, i1 false)
+ %tobool = icmp eq i32 %a, 0
+ %sub1 = xor i32 %lz, 31
+ %cond = select i1 %tobool, i32 31, i32 %sub1
+ ret i32 %cond
+}
+
define i4 @PR45762(i3 %x4) {
; CHECK-LABEL: @PR45762(
; CHECK-NEXT: [[T4:%.*]] = call i3 @llvm.cttz.i3(i3 [[X4:%.*]], i1 false), !range [[RNG2:![0-9]+]]
More information about the llvm-commits
mailing list