Skip to content

Commit 09e19cf

Browse files
authored
llvm-reduce: Do not reduce alloca array sizes to 0 (#132864)
Fixes #64340
1 parent 528e408 commit 09e19cf

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=operands-zero --test FileCheck --test-arg --check-prefix=CHECK --test-arg %s --test-arg --input-file %s -o %t
2+
; RUN: FileCheck %s --check-prefixes=CHECK,ZERO < %t
3+
4+
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=operands-one --test FileCheck --test-arg --check-prefix=CHECK --test-arg %s --test-arg --input-file %s -o %t
5+
; RUN: FileCheck %s --check-prefixes=CHECK,ONE < %t
6+
7+
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=operands-poison --test FileCheck --test-arg --check-prefix=CHECK --test-arg %s --test-arg --input-file %s -o %t
8+
; RUN: FileCheck %s --check-prefixes=CHECK,POISON < %t
9+
10+
11+
; CHECK-LABEL: @dyn_alloca(
12+
; ZERO: %alloca = alloca i32, i32 %size, align 4
13+
; ONE: %alloca = alloca i32, align 4
14+
; POISON: %alloca = alloca i32, i32 %size, align 4
15+
define void @dyn_alloca(i32 %size) {
16+
%alloca = alloca i32, i32 %size
17+
store i32 0, ptr %alloca
18+
ret void
19+
}
20+
21+
; CHECK-LABEL: @alloca_0_elt(
22+
; ZERO: %alloca = alloca i32, i32 0, align 4
23+
; ONE: %alloca = alloca i32, i32 0, align 4
24+
; POISON: %alloca = alloca i32, i32 0, align 4
25+
define void @alloca_0_elt() {
26+
%alloca = alloca i32, i32 0
27+
store i32 0, ptr %alloca
28+
ret void
29+
}
30+
31+
; CHECK-LABEL: @alloca_1_elt(
32+
; ZERO: %alloca = alloca i32, align 4
33+
; ONE: %alloca = alloca i32, align 4
34+
; POISON: %alloca = alloca i32, align 4
35+
define void @alloca_1_elt() {
36+
%alloca = alloca i32, i32 1
37+
store i32 0, ptr %alloca
38+
ret void
39+
}
40+
41+
; CHECK-LABEL: @alloca_1024_elt(
42+
; ZERO: %alloca = alloca i32, i32 1024, align 4
43+
; ONE: %alloca = alloca i32, align 4
44+
; POISON: %alloca = alloca i32, i32 1024, align 4
45+
define void @alloca_1024_elt() {
46+
%alloca = alloca i32, i32 1024
47+
store i32 0, ptr %alloca
48+
ret void
49+
}
50+
51+
; CHECK-LABEL: @alloca_poison_elt(
52+
; ZERO: %alloca = alloca i32, i32 poison, align 4
53+
; ONE: %alloca = alloca i32, align 4
54+
; POISON: %alloca = alloca i32, i32 poison, align 4
55+
define void @alloca_poison_elt() {
56+
%alloca = alloca i32, i32 poison
57+
store i32 0, ptr %alloca
58+
ret void
59+
}
60+
61+
; CHECK-LABEL: @alloca_constexpr_elt(
62+
; ZERO: %alloca = alloca i32, i32 ptrtoint (ptr @alloca_constexpr_elt to i32)
63+
; ONE: %alloca = alloca i32, align 4
64+
; POISON: %alloca = alloca i32, i32 ptrtoint (ptr @alloca_constexpr_elt to i32)
65+
define void @alloca_constexpr_elt() {
66+
%alloca = alloca i32, i32 ptrtoint (ptr @alloca_constexpr_elt to i32)
67+
store i32 0, ptr %alloca
68+
ret void
69+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ void llvm::reduceOperandsZeroDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {
125125
auto ReduceValue = [](Use &Op) -> Value * {
126126
if (!shouldReduceOperand(Op))
127127
return nullptr;
128+
129+
// Avoid introducing 0-sized allocations.
130+
if (isa<AllocaInst>(Op.getUser()))
131+
return nullptr;
132+
128133
// Don't duplicate an existing switch case.
129134
if (auto *IntTy = dyn_cast<IntegerType>(Op->getType()))
130135
if (switchCaseExists(Op, ConstantInt::get(IntTy, 0)))

0 commit comments

Comments
 (0)