[InstSimplify] cttz(1<<x) --> x

https://alive2.llvm.org/ce/z/TDacYu
https://alive2.llvm.org/ce/z/KF84S3
This commit is contained in:
Sanjay Patel
2021-03-08 15:42:01 -05:00
parent afa443831b
commit 0a2d69480d
2 changed files with 8 additions and 6 deletions

View File

@@ -5485,6 +5485,12 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
return Op0;
break;
case Intrinsic::cttz: {
Value *X;
if (match(Op0, m_Shl(m_One(), m_Value(X))))
return X;
break;
}
case Intrinsic::smax:
case Intrinsic::smin:
case Intrinsic::umax:

View File

@@ -1365,9 +1365,7 @@ declare <3 x i33> @llvm.cttz.v3i33(<3 x i33>, i1)
define i32 @cttz_shl1(i32 %x) {
; CHECK-LABEL: @cttz_shl1(
; CHECK-NEXT: [[S:%.*]] = shl i32 1, [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = call i32 @llvm.cttz.i32(i32 [[S]], i1 true)
; CHECK-NEXT: ret i32 [[R]]
; CHECK-NEXT: ret i32 [[X:%.*]]
;
%s = shl i32 1, %x
%r = call i32 @llvm.cttz.i32(i32 %s, i1 true)
@@ -1376,9 +1374,7 @@ define i32 @cttz_shl1(i32 %x) {
define <3 x i33> @cttz_shl1_vec(<3 x i33> %x) {
; CHECK-LABEL: @cttz_shl1_vec(
; CHECK-NEXT: [[S:%.*]] = shl <3 x i33> <i33 1, i33 1, i33 undef>, [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = call <3 x i33> @llvm.cttz.v3i33(<3 x i33> [[S]], i1 false)
; CHECK-NEXT: ret <3 x i33> [[R]]
; CHECK-NEXT: ret <3 x i33> [[X:%.*]]
;
%s = shl <3 x i33> <i33 1, i33 1, i33 undef>, %x
%r = call <3 x i33> @llvm.cttz.v3i33(<3 x i33> %s, i1 false)