[llvm] c8bc1ab - [InstCombine] Add tests for cttz of lowest set bit (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 14 05:31:44 PDT 2023
Author: Nikita Popov
Date: 2023-07-14T14:31:35+02:00
New Revision: c8bc1abf55551741fbd887ec1b293c45065ac022
URL: https://github.com/llvm/llvm-project/commit/c8bc1abf55551741fbd887ec1b293c45065ac022
DIFF: https://github.com/llvm/llvm-project/commit/c8bc1abf55551741fbd887ec1b293c45065ac022.diff
LOG: [InstCombine] Add tests for cttz of lowest set bit (NFC)
Added:
Modified:
llvm/test/Transforms/InstCombine/cttz.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/cttz.ll b/llvm/test/Transforms/InstCombine/cttz.ll
index 197eae184f8c3a..74ce48589346c9 100644
--- a/llvm/test/Transforms/InstCombine/cttz.ll
+++ b/llvm/test/Transforms/InstCombine/cttz.ll
@@ -2,6 +2,7 @@
; RUN: opt < %s -S -passes=instcombine | FileCheck %s
declare i32 @llvm.cttz.i32(i32, i1)
+declare i32 @llvm.ctlz.i32(i32, i1)
declare <2 x i64> @llvm.cttz.v2i64(<2 x i64>, i1)
declare void @use(i32)
@@ -118,3 +119,109 @@ define <2 x i64> @cttz_sext_zero_def_vec(<2 x i32> %x) {
%tz = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %s, i1 false)
ret <2 x i64> %tz
}
+
+define i32 @cttz_of_lowest_set_bit(i32 %x) {
+; CHECK-LABEL: @cttz_of_lowest_set_bit(
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[X:%.*]]
+; CHECK-NEXT: [[AND:%.*]] = and i32 [[SUB]], [[X]]
+; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[AND]], i1 false), !range [[RNG1]]
+; CHECK-NEXT: ret i32 [[TZ]]
+;
+ %sub = sub i32 0, %x
+ %and = and i32 %sub, %x
+ %tz = call i32 @llvm.cttz.i32(i32 %and, i1 false)
+ ret i32 %tz
+}
+
+define i32 @cttz_of_lowest_set_bit_commuted(i32 %xx) {
+; CHECK-LABEL: @cttz_of_lowest_set_bit_commuted(
+; CHECK-NEXT: [[X:%.*]] = udiv i32 42, [[XX:%.*]]
+; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
+; CHECK-NEXT: [[AND:%.*]] = and i32 [[X]], [[SUB]]
+; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[AND]], i1 false), !range [[RNG1]]
+; CHECK-NEXT: ret i32 [[TZ]]
+;
+ %x = udiv i32 42, %xx ; thwart complexity-based canonicalization
+ %sub = sub i32 0, %x
+ %and = and i32 %x, %sub
+ %tz = call i32 @llvm.cttz.i32(i32 %and, i1 false)
+ ret i32 %tz
+}
+
+define i32 @cttz_of_lowest_set_bit_poison_flag(i32 %x) {
+; CHECK-LABEL: @cttz_of_lowest_set_bit_poison_flag(
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[X:%.*]]
+; CHECK-NEXT: [[AND:%.*]] = and i32 [[SUB]], [[X]]
+; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[AND]], i1 true), !range [[RNG1]]
+; CHECK-NEXT: ret i32 [[TZ]]
+;
+ %sub = sub i32 0, %x
+ %and = and i32 %sub, %x
+ %tz = call i32 @llvm.cttz.i32(i32 %and, i1 true)
+ ret i32 %tz
+}
+
+define <2 x i64> @cttz_of_lowest_set_bit_vec(<2 x i64> %x) {
+; CHECK-LABEL: @cttz_of_lowest_set_bit_vec(
+; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i64> zeroinitializer, [[X:%.*]]
+; CHECK-NEXT: [[AND:%.*]] = and <2 x i64> [[SUB]], [[X]]
+; CHECK-NEXT: [[TZ:%.*]] = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[AND]], i1 false), !range [[RNG2]]
+; CHECK-NEXT: ret <2 x i64> [[TZ]]
+;
+ %sub = sub <2 x i64> zeroinitializer, %x
+ %and = and <2 x i64> %sub, %x
+ %tz = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %and, i1 false)
+ ret <2 x i64> %tz
+}
+
+define <2 x i64> @cttz_of_lowest_set_bit_vec_undef(<2 x i64> %x) {
+; CHECK-LABEL: @cttz_of_lowest_set_bit_vec_undef(
+; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i64> zeroinitializer, [[X:%.*]]
+; CHECK-NEXT: [[AND:%.*]] = and <2 x i64> [[SUB]], [[X]]
+; CHECK-NEXT: [[TZ:%.*]] = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[AND]], i1 false), !range [[RNG2]]
+; CHECK-NEXT: ret <2 x i64> [[TZ]]
+;
+ %sub = sub <2 x i64> zeroinitializer, %x
+ %and = and <2 x i64> %sub, %x
+ %tz = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %and, i1 false)
+ ret <2 x i64> %tz
+}
+
+define i32 @cttz_of_lowest_set_bit_wrong_const(i32 %x) {
+; CHECK-LABEL: @cttz_of_lowest_set_bit_wrong_const(
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 1, [[X:%.*]]
+; CHECK-NEXT: [[AND:%.*]] = and i32 [[SUB]], [[X]]
+; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[AND]], i1 false), !range [[RNG3:![0-9]+]]
+; CHECK-NEXT: ret i32 [[TZ]]
+;
+ %sub = sub i32 1, %x
+ %and = and i32 %sub, %x
+ %tz = call i32 @llvm.cttz.i32(i32 %and, i1 false)
+ ret i32 %tz
+}
+
+define i32 @cttz_of_lowest_set_bit_wrong_operand(i32 %x, i32 %y) {
+; CHECK-LABEL: @cttz_of_lowest_set_bit_wrong_operand(
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[Y:%.*]]
+; CHECK-NEXT: [[AND:%.*]] = and i32 [[SUB]], [[X:%.*]]
+; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[AND]], i1 false), !range [[RNG1]]
+; CHECK-NEXT: ret i32 [[TZ]]
+;
+ %sub = sub i32 0, %y
+ %and = and i32 %sub, %x
+ %tz = call i32 @llvm.cttz.i32(i32 %and, i1 false)
+ ret i32 %tz
+}
+
+define i32 @cttz_of_lowest_set_bit_wrong_intrinsic(i32 %x) {
+; CHECK-LABEL: @cttz_of_lowest_set_bit_wrong_intrinsic(
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[X:%.*]]
+; CHECK-NEXT: [[AND:%.*]] = and i32 [[SUB]], [[X]]
+; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.ctlz.i32(i32 [[AND]], i1 false), !range [[RNG1]]
+; CHECK-NEXT: ret i32 [[TZ]]
+;
+ %sub = sub i32 0, %x
+ %and = and i32 %sub, %x
+ %tz = call i32 @llvm.ctlz.i32(i32 %and, i1 false)
+ ret i32 %tz
+}
More information about the llvm-commits
mailing list