Skip to content

Commit e26a702

Browse files
Apply suggestions from code review
Co-authored-by: Nikita Popov <[email protected]>
1 parent 74fc5e1 commit e26a702

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,8 +1791,8 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
17911791
// (X >> log2(N)) + zext(X & (N-1) != 0) --> (X + (N-1)) >> log2(N)
17921792
// This is valid when adding (N-1) to X doesn't overflow.
17931793
{
1794-
Value *X = nullptr;
1795-
const APInt *ShiftAmt = nullptr, *Mask = nullptr;
1794+
Value *X;
1795+
const APInt *ShiftAmt, *Mask;
17961796
CmpPredicate Pred;
17971797

17981798
// Match: (X >> C) + zext((X & Mask) != 0)
@@ -1806,9 +1806,7 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
18061806

18071807
// Check if X + Mask doesn't overflow
18081808
Constant *MaskC = ConstantInt::get(X->getType(), *Mask);
1809-
bool WillNotOverflowUnsigned = willNotOverflowUnsignedAdd(X, MaskC, I);
1810-
1811-
if (WillNotOverflowUnsigned) {
1809+
if (willNotOverflowUnsignedAdd(X, MaskC, I)) {
18121810
// (X + Mask) >> ShiftAmt
18131811
Value *Add = Builder.CreateNUWAdd(X, MaskC);
18141812
return BinaryOperator::CreateLShr(

llvm/test/Transforms/InstCombine/add.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4279,7 +4279,7 @@ declare i32 @llvm.ctlz.i32(i32, i1)
42794279
; This is only valid when x + (N-1) doesn't overflow
42804280

42814281
; Test with known range that prevents overflow
4282-
define noundef range(i32 0, 100) i32 @ceil_div_by_8_known_range(i32 noundef range(i32 0, 100) %x) {
4282+
define i32 @ceil_div_by_8_known_range(i32 range(i32 0, 100) %x) {
42834283
; CHECK-LABEL: @ceil_div_by_8_known_range(
42844284
; CHECK-NEXT: [[TMP1:%.*]] = add nuw nsw i32 [[X:%.*]], 7
42854285
; CHECK-NEXT: [[R:%.*]] = lshr i32 [[TMP1]], 3
@@ -4294,7 +4294,7 @@ define noundef range(i32 0, 100) i32 @ceil_div_by_8_known_range(i32 noundef rang
42944294
}
42954295

42964296
; Test with the exact IR from the original testcase
4297-
define noundef range(i32 0, 6) i32 @ceil_div_from_clz(i32 noundef %v) {
4297+
define i32 @ceil_div_from_clz(i32 %v) {
42984298
; CHECK-LABEL: @ceil_div_from_clz(
42994299
; CHECK-NEXT: [[CTLZ:%.*]] = tail call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 [[V:%.*]], i1 false)
43004300
; CHECK-NEXT: [[TMP1:%.*]] = sub nuw nsw i32 39, [[CTLZ]]

0 commit comments

Comments
 (0)