Skip to content

Commit 29f5d16

Browse files
committed
Revert "[InstCombine] avoid crash from deleting an instruction that still has uses (PR43723) (3rd try)"
This reverts commit 3db8a3e. This caused a different memory-sanitizer failure than earlier attempts, but it's still not right.
1 parent 3db8a3e commit 29f5d16

File tree

2 files changed

+4
-53
lines changed

2 files changed

+4
-53
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,21 +2340,13 @@ static bool isAllocSiteRemovable(Instruction *AI,
23402340
return false;
23412341
LLVM_FALLTHROUGH;
23422342
}
2343+
case Intrinsic::invariant_start:
23432344
case Intrinsic::invariant_end:
23442345
case Intrinsic::lifetime_start:
23452346
case Intrinsic::lifetime_end:
23462347
case Intrinsic::objectsize:
23472348
Users.emplace_back(I);
23482349
continue;
2349-
case Intrinsic::invariant_start:
2350-
// Only delete this if it has no uses or a single 'end' use.
2351-
if (I->use_empty())
2352-
Users.emplace_back(I);
2353-
else if (I->hasOneUse() &&
2354-
match(I->user_back(),
2355-
m_Intrinsic<Intrinsic::invariant_end>()))
2356-
Users.emplace_back(I);
2357-
continue;
23582350
}
23592351
}
23602352

@@ -2402,27 +2394,21 @@ Instruction *InstCombiner::visitAllocSite(Instruction &MI) {
24022394

24032395
if (isAllocSiteRemovable(&MI, Users, &TLI)) {
24042396
for (unsigned i = 0, e = Users.size(); i != e; ++i) {
2397+
// Lowering all @llvm.objectsize calls first because they may
2398+
// use a bitcast/GEP of the alloca we are removing.
24052399
if (!Users[i])
24062400
continue;
24072401

24082402
Instruction *I = cast<Instruction>(&*Users[i]);
2403+
24092404
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
2410-
// Lowering all @llvm.objectsize calls first because they may
2411-
// use a bitcast/GEP of the alloca we are removing.
24122405
if (II->getIntrinsicID() == Intrinsic::objectsize) {
24132406
Value *Result =
24142407
lowerObjectSizeCall(II, DL, &TLI, /*MustSucceed=*/true);
24152408
replaceInstUsesWith(*I, Result);
24162409
eraseInstFromFunction(*I);
24172410
Users[i] = nullptr; // Skip examining in the next loop.
24182411
}
2419-
// Erase llvm.invariant.start because we expect that it is used by
2420-
// llvm.invariant.end that we will remove below.
2421-
if (II->getIntrinsicID() == Intrinsic::invariant_start) {
2422-
replaceInstUsesWith(*I, UndefValue::get(I->getType()));
2423-
eraseInstFromFunction(*I);
2424-
Users[i] = nullptr; // Skip examining in the next loop.
2425-
}
24262412
}
24272413
}
24282414
for (unsigned i = 0, e = Users.size(); i != e; ++i) {

llvm/test/Transforms/InstCombine/builtin-object-size-ptr.ll

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,6 @@ define i32 @foo() #0 {
2828
ret i32 %conv
2929
}
3030

31-
; This used to crash while erasing instructions:
32-
; https://bugs.llvm.org/show_bug.cgi?id=43723
33-
34-
define void @PR43723() {
35-
; CHECK-LABEL: @PR43723(
36-
; CHECK-NEXT: ret void
37-
;
38-
%tab = alloca [10 x i8], align 16
39-
%t0 = bitcast [10 x i8]* %tab to i8*
40-
call void @llvm.memset.p0i8.i64(i8* align 16 %t0, i8 9, i64 10, i1 false)
41-
%t1 = call {}* @llvm.invariant.start.p0i8(i64 10, i8* align 16 %t0)
42-
call void @llvm.invariant.end.p0i8({}* %t1, i64 10, i8* align 16 %t0)
43-
ret void
44-
45-
uselistorder i8* %t0, { 1, 0, 2 }
46-
}
47-
48-
define void @unknown_use_of_invariant_start({}** %p) {
49-
; CHECK-LABEL: @unknown_use_of_invariant_start(
50-
; CHECK-NEXT: [[T1:%.*]] = call {}* @llvm.invariant.start.p0i8(i64 10, i8* align 16 undef)
51-
; CHECK-NEXT: store {}* [[T1]], {}** [[P:%.*]], align 8
52-
; CHECK-NEXT: ret void
53-
;
54-
%tab = alloca [10 x i8], align 16
55-
%t0 = bitcast [10 x i8]* %tab to i8*
56-
call void @llvm.memset.p0i8.i64(i8* align 16 %t0, i8 9, i64 10, i1 false)
57-
%t1 = call {}* @llvm.invariant.start.p0i8(i64 10, i8* align 16 %t0)
58-
call void @llvm.invariant.end.p0i8({}* %t1, i64 10, i8* align 16 %t0)
59-
store {}* %t1, {}** %p
60-
ret void
61-
}
62-
6331
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
6432
declare i64 @llvm.objectsize.i64.p0i8(i8*, i1) #2
6533
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
66-
declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg) #0
67-
declare {}* @llvm.invariant.start.p0i8(i64 immarg, i8* nocapture) #0
68-
declare void @llvm.invariant.end.p0i8({}*, i64 immarg, i8* nocapture) #0

0 commit comments

Comments
 (0)