Skip to content

Commit f43daa3

Browse files
committed
[CodeGenPrepare] Drop nsw flags in optimizeLoadExt
1 parent 8583154 commit f43daa3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7138,6 +7138,7 @@ bool CodeGenPrepare::optimizeLoadExt(LoadInst *Load) {
71387138
SmallVector<Instruction *, 8> WorkList;
71397139
SmallPtrSet<Instruction *, 16> Visited;
71407140
SmallVector<Instruction *, 8> AndsToMaybeRemove;
7141+
SmallVector<Instruction *, 8> DropFlags;
71417142
for (auto *U : Load->users())
71427143
WorkList.push_back(cast<Instruction>(U));
71437144

@@ -7185,13 +7186,15 @@ bool CodeGenPrepare::optimizeLoadExt(LoadInst *Load) {
71857186
return false;
71867187
uint64_t ShiftAmt = ShlC->getLimitedValue(BitWidth - 1);
71877188
DemandBits.setLowBits(BitWidth - ShiftAmt);
7189+
DropFlags.push_back(I);
71887190
break;
71897191
}
71907192

71917193
case Instruction::Trunc: {
71927194
EVT TruncVT = TLI->getValueType(*DL, I->getType());
71937195
unsigned TruncBitWidth = TruncVT.getSizeInBits();
71947196
DemandBits.setLowBits(TruncBitWidth);
7197+
DropFlags.push_back(I);
71957198
break;
71967199
}
71977200

@@ -7249,6 +7252,10 @@ bool CodeGenPrepare::optimizeLoadExt(LoadInst *Load) {
72497252
++NumAndUses;
72507253
}
72517254

7255+
// NSW flags may not longer hold.
7256+
for (auto *Inst : DropFlags)
7257+
Inst->setHasNoSignedWrap(false);
7258+
72527259
++NumAndsAdded;
72537260
return true;
72547261
}

llvm/test/Transforms/CodeGenPrepare/X86/pr118172.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ define i32 @simplify_load_ext_drop_trunc_nsw(ptr %p) {
88
; CHECK-NEXT: [[ENTRY:.*:]]
99
; CHECK-NEXT: [[X:%.*]] = load i32, ptr [[P]], align 4
1010
; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[X]], 255
11-
; CHECK-NEXT: [[TRUNC:%.*]] = trunc nsw i32 [[TMP0]] to i8
11+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 [[TMP0]] to i8
1212
; CHECK-NEXT: [[EXT1:%.*]] = sext i8 [[TRUNC]] to i16
1313
; CHECK-NEXT: call void @use(i32 [[TMP0]])
1414
; CHECK-NEXT: [[EXT2:%.*]] = zext i16 [[EXT1]] to i32
@@ -31,7 +31,7 @@ define i32 @simplify_load_ext_drop_shl_nsw(ptr %p) {
3131
; CHECK-NEXT: [[ENTRY:.*:]]
3232
; CHECK-NEXT: [[X:%.*]] = load i32, ptr [[P]], align 4
3333
; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[X]], 255
34-
; CHECK-NEXT: [[SHL:%.*]] = shl nsw i32 [[TMP0]], 24
34+
; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[TMP0]], 24
3535
; CHECK-NEXT: call void @use(i32 [[TMP0]])
3636
; CHECK-NEXT: ret i32 [[SHL]]
3737
;

0 commit comments

Comments
 (0)