Skip to content

Commit bf09a92

Browse files
committed
[InstCombine] remove likely redundant ValueTracking-based folds for shifts
This is not expected to have a functional difference as discussed in the post-commit comments for 8a9c70f. All of the motivating tests for the older fold still optimize as expected because other code can infer the 'nuw'.
1 parent 9209a51 commit bf09a92

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,16 +399,15 @@ Instruction *InstCombinerImpl::commonShiftTransforms(BinaryOperator &I) {
399399
reassociateShiftAmtsOfTwoSameDirectionShifts(&I, SQ)))
400400
return NewShift;
401401

402-
// C0 shift (A add C) -> (C0 shift C) shift A
403-
// iff A and C2 are both positive or the add has 'nuw'.
402+
// Pre-shift a constant shifted by a variable amount with constant offset:
403+
// C shift (A add nuw C1) --> (C shift C1) shift A
404404
Value *A;
405-
Constant *C;
406-
if (match(Op0, m_Constant()) && match(Op1, m_Add(m_Value(A), m_Constant(C))))
407-
if (cast<BinaryOperator>(Op1)->hasNoUnsignedWrap() ||
408-
(isKnownNonNegative(A, DL, 0, &AC, &I, &DT) &&
409-
isKnownNonNegative(C, DL, 0, &AC, &I, &DT)))
410-
return BinaryOperator::Create(
411-
I.getOpcode(), Builder.CreateBinOp(I.getOpcode(), Op0, C), A);
405+
Constant *C, *C1;
406+
if (match(Op0, m_Constant(C)) &&
407+
match(Op1, m_NUWAdd(m_Value(A), m_Constant(C1)))) {
408+
Constant *NewC = ConstantExpr::get(I.getOpcode(), C, C1);
409+
return BinaryOperator::Create(I.getOpcode(), NewC, A);
410+
}
412411

413412
// X shift (A srem C) -> X shift (A and (C - 1)) iff C is a power of 2.
414413
// Because shifts by negative values (which could occur if A were negative)

0 commit comments

Comments
 (0)