Skip to content

Commit e4b0655

Browse files
authored
[InstCombine] Fix missing argument typo in InstCombinerImpl::foldICmpShlConstant (#94899)
Closes #94897.
1 parent add8908 commit e4b0655

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,9 +2441,10 @@ Instruction *InstCombinerImpl::foldICmpShlConstant(ICmpInst &Cmp,
24412441
Type *TruncTy = ShType->getWithNewBitWidth(TypeBits - Amt);
24422442
Constant *NewC =
24432443
ConstantInt::get(TruncTy, RHSC.ashr(*ShiftAmt).trunc(TypeBits - Amt));
2444-
return new ICmpInst(
2445-
CmpPred, Builder.CreateTrunc(X, TruncTy, "", Shl->hasNoSignedWrap()),
2446-
NewC);
2444+
return new ICmpInst(CmpPred,
2445+
Builder.CreateTrunc(X, TruncTy, "", /*IsNUW=*/false,
2446+
Shl->hasNoSignedWrap()),
2447+
NewC);
24472448
}
24482449
}
24492450

llvm/test/Transforms/InstCombine/icmp.ll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5255,6 +5255,16 @@ define i1 @test_icmp_shl_nuw(i64 %x) {
52555255
ret i1 %cmp
52565256
}
52575257

5258+
define i1 @test_icmp_shl_nuw_i31(i31 %x) {
5259+
; CHECK-LABEL: @test_icmp_shl_nuw_i31(
5260+
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i31 [[X:%.*]], 250
5261+
; CHECK-NEXT: ret i1 [[CMP]]
5262+
;
5263+
%shl = shl nuw i31 %x, 23
5264+
%cmp = icmp ugt i31 %shl, -50331648
5265+
ret i1 %cmp
5266+
}
5267+
52585268
define i1 @test_icmp_shl_nsw(i64 %x) {
52595269
; CHECK-LABEL: @test_icmp_shl_nsw(
52605270
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 3
@@ -5265,6 +5275,17 @@ define i1 @test_icmp_shl_nsw(i64 %x) {
52655275
ret i1 %cmp
52665276
}
52675277

5278+
define i1 @test_icmp_shl_nsw_i31(i31 %x) {
5279+
; CHECK-LABEL: @test_icmp_shl_nsw_i31(
5280+
; CHECK-NEXT: [[TMP1:%.*]] = trunc nsw i31 [[X:%.*]] to i8
5281+
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[TMP1]], -6
5282+
; CHECK-NEXT: ret i1 [[CMP]]
5283+
;
5284+
%shl = shl nsw i31 %x, 23
5285+
%cmp = icmp ugt i31 %shl, -50331648
5286+
ret i1 %cmp
5287+
}
5288+
52685289
define <2 x i1> @test_icmp_shl_vec(<2 x i64> %x) {
52695290
; CHECK-LABEL: @test_icmp_shl_vec(
52705291
; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i64> [[X:%.*]] to <2 x i32>
@@ -5295,3 +5316,13 @@ define i1 @test_icmp_shl_sgt(i64 %x) {
52955316
%cmp = icmp sgt i64 %shl, 8589934591
52965317
ret i1 %cmp
52975318
}
5319+
5320+
define i1 @pr94897(i32 range(i32 -2147483648, 0) %x) {
5321+
; CHECK-LABEL: @pr94897(
5322+
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[X:%.*]], -3
5323+
; CHECK-NEXT: ret i1 [[CMP]]
5324+
;
5325+
%shl = shl nsw i32 %x, 24
5326+
%cmp = icmp ugt i32 %shl, -50331648
5327+
ret i1 %cmp
5328+
}

0 commit comments

Comments
 (0)