Skip to content

[InstCombine] Fix missing argument typo in InstCombinerImpl::foldICmpShlConstant #94899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2441,9 +2441,10 @@ Instruction *InstCombinerImpl::foldICmpShlConstant(ICmpInst &Cmp,
Type *TruncTy = ShType->getWithNewBitWidth(TypeBits - Amt);
Constant *NewC =
ConstantInt::get(TruncTy, RHSC.ashr(*ShiftAmt).trunc(TypeBits - Amt));
return new ICmpInst(
CmpPred, Builder.CreateTrunc(X, TruncTy, "", Shl->hasNoSignedWrap()),
NewC);
return new ICmpInst(CmpPred,
Builder.CreateTrunc(X, TruncTy, "", /*IsNUW=*/false,
Shl->hasNoSignedWrap()),
NewC);
}
}

Expand Down
31 changes: 31 additions & 0 deletions llvm/test/Transforms/InstCombine/icmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5255,6 +5255,16 @@ define i1 @test_icmp_shl_nuw(i64 %x) {
ret i1 %cmp
}

define i1 @test_icmp_shl_nuw_i31(i31 %x) {
; CHECK-LABEL: @test_icmp_shl_nuw_i31(
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i31 [[X:%.*]], 250
; CHECK-NEXT: ret i1 [[CMP]]
;
%shl = shl nuw i31 %x, 23
%cmp = icmp ugt i31 %shl, -50331648
ret i1 %cmp
}

define i1 @test_icmp_shl_nsw(i64 %x) {
; CHECK-LABEL: @test_icmp_shl_nsw(
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 3
Expand All @@ -5265,6 +5275,17 @@ define i1 @test_icmp_shl_nsw(i64 %x) {
ret i1 %cmp
}

define i1 @test_icmp_shl_nsw_i31(i31 %x) {
; CHECK-LABEL: @test_icmp_shl_nsw_i31(
; CHECK-NEXT: [[TMP1:%.*]] = trunc nsw i31 [[X:%.*]] to i8
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[TMP1]], -6
; CHECK-NEXT: ret i1 [[CMP]]
;
%shl = shl nsw i31 %x, 23
%cmp = icmp ugt i31 %shl, -50331648
ret i1 %cmp
}

define <2 x i1> @test_icmp_shl_vec(<2 x i64> %x) {
; CHECK-LABEL: @test_icmp_shl_vec(
; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i64> [[X:%.*]] to <2 x i32>
Expand Down Expand Up @@ -5295,3 +5316,13 @@ define i1 @test_icmp_shl_sgt(i64 %x) {
%cmp = icmp sgt i64 %shl, 8589934591
ret i1 %cmp
}

define i1 @pr94897(i32 range(i32 -2147483648, 0) %x) {
; CHECK-LABEL: @pr94897(
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[X:%.*]], -3
; CHECK-NEXT: ret i1 [[CMP]]
;
%shl = shl nsw i32 %x, 24
%cmp = icmp ugt i32 %shl, -50331648
ret i1 %cmp
}
Loading