File tree 2 files changed +28
-1
lines changed 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -3369,11 +3369,17 @@ void llvm::patchReplacementInstruction(Instruction *I, Value *Repl) {
3369
3369
3370
3370
// Patch the replacement so that it is not more restrictive than the value
3371
3371
// being replaced.
3372
+ WithOverflowInst *UnusedWO;
3373
+ // When replacing the result of a llvm.*.with.overflow intrinsic with a
3374
+ // overflowing binary operator, nuw/nsw flags may no longer hold.
3375
+ if (isa<OverflowingBinaryOperator>(ReplInst) &&
3376
+ match (I, m_ExtractValue<0 >(m_WithOverflowInst (UnusedWO))))
3377
+ ReplInst->dropPoisonGeneratingFlags ();
3372
3378
// Note that if 'I' is a load being replaced by some operation,
3373
3379
// for example, by an arithmetic operation, then andIRFlags()
3374
3380
// would just erase all math flags from the original arithmetic
3375
3381
// operation, which is clearly not wanted and not needed.
3376
- if (!isa<LoadInst>(I))
3382
+ else if (!isa<LoadInst>(I))
3377
3383
ReplInst->andIRFlags (I);
3378
3384
3379
3385
// FIXME: If both the original and replacement value are part of the
Original file line number Diff line number Diff line change
1
+ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2
+ ; RUN: opt -S -passes=gvn < %s | FileCheck %s
3
+
4
+ ; Make sure nsw/nuw flags are dropped.
5
+
6
+ define i32 @pr82884 (i32 %x ) {
7
+ ; CHECK-LABEL: define i32 @pr82884(
8
+ ; CHECK-SAME: i32 [[X:%.*]]) {
9
+ ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[X]], [[X]]
10
+ ; CHECK-NEXT: call void @use(i32 [[MUL]])
11
+ ; CHECK-NEXT: [[MUL2:%.*]] = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 [[X]], i32 [[X]])
12
+ ; CHECK-NEXT: ret i32 [[MUL]]
13
+ ;
14
+ %mul = mul nsw nuw i32 %x , %x
15
+ call void @use (i32 %mul )
16
+ %mul2 = call { i32 , i1 } @llvm.smul.with.overflow.i32 (i32 %x , i32 %x )
17
+ %ret = extractvalue { i32 , i1 } %mul2 , 0
18
+ ret i32 %ret
19
+ }
20
+
21
+ declare void @use (i32 )
You can’t perform that action at this time.
0 commit comments