Skip to content

Commit 48a0a3b

Browse files
authored
[llvm-reduce] Do not replace alloca with null pointers (#164075)
The lifetime intrinsics only accept allocas or poison. This patch uses poison as the replacement value of alloca.
1 parent 8e5f6dd commit 48a0a3b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=instructions --test FileCheck --test-arg --check-prefixes=CHECK,INTERESTING --test-arg %s --test-arg --input-file %s -o %t
2+
; RUN: FileCheck -check-prefixes=CHECK,RESULT %s < %t
3+
4+
; CHECK-LABEL: define void @alloca(
5+
; INTERESTING: call void @llvm.lifetime.start.p0(
6+
; INTERESTING: call void @llvm.lifetime.end.p0(
7+
8+
; RESULT: call void @llvm.lifetime.start.p0(ptr poison)
9+
; RESULT-NEXT: call void @llvm.lifetime.end.p0(ptr poison)
10+
; RESULT-NEXT: ret void
11+
define void @alloca(ptr %ptr) {
12+
%alloca = alloca i32, align 4
13+
call void @llvm.lifetime.start.p0(ptr %alloca)
14+
call void @llvm.lifetime.end.p0(ptr %alloca)
15+
ret void
16+
}

llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#include "ReduceInstructions.h"
1515
#include "Utils.h"
16+
#include "llvm/IR/Constants.h"
17+
#include "llvm/IR/Instructions.h"
1618

1719
using namespace llvm;
1820

@@ -37,7 +39,9 @@ void llvm::reduceInstructionsDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {
3739
for (auto &Inst :
3840
make_early_inc_range(make_range(BB.begin(), std::prev(BB.end())))) {
3941
if (!shouldAlwaysKeep(Inst) && !O.shouldKeep()) {
40-
Inst.replaceAllUsesWith(getDefaultValue(Inst.getType()));
42+
Inst.replaceAllUsesWith(isa<AllocaInst>(Inst)
43+
? PoisonValue::get(Inst.getType())
44+
: getDefaultValue(Inst.getType()));
4145
Inst.eraseFromParent();
4246
}
4347
}

0 commit comments

Comments
 (0)