Skip to content

Commit 212f344

Browse files
committed
[InstCombine] Handle constant expression result in tryFactorization()
If IRBuilder folds the result to a constant expression, don't try to set nowrap flags on it. Fixes #124526.
1 parent e14962a commit 212f344

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ static Value *tryFactorization(BinaryOperator &I, const SimplifyQuery &SQ,
732732
RetVal->takeName(&I);
733733

734734
// Try to add no-overflow flags to the final value.
735-
if (isa<OverflowingBinaryOperator>(RetVal)) {
735+
if (isa<BinaryOperator>(RetVal)) {
736736
bool HasNSW = false;
737737
bool HasNUW = false;
738738
if (isa<OverflowingBinaryOperator>(&I)) {

llvm/test/Transforms/InstCombine/add2.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,17 @@ define i16 @mul_add_to_mul_9(i16 %a) {
321321
ret i16 %add
322322
}
323323

324+
@g = external global i8
325+
326+
define i32 @shl_add_to_shl_constexpr() {
327+
; CHECK-LABEL: @shl_add_to_shl_constexpr(
328+
; CHECK-NEXT: ret i32 mul (i32 ptrtoint (ptr @g to i32), i32 4)
329+
;
330+
%shl = shl i32 ptrtoint (ptr @g to i32), 1
331+
%add = add i32 %shl, %shl
332+
ret i32 %add
333+
}
334+
324335
; This test and the next test verify that when a range metadata is attached to
325336
; llvm.cttz, ValueTracking correctly intersects the range specified by the
326337
; metadata and the range implied by the intrinsic.

0 commit comments

Comments
 (0)