Skip to content

Commit 6773435

Browse files
committed
[IPCP] Bail on extractvalue's with more than 1 index.
The replacement code only looks at the first index of the extractvalue. If there are additional indices we'll end up doing a bad replacement. This only happens if the function returns a nested struct. Not sure if clang ever generates such code. The original report came from ispc. Fixes PR43857 Differential Revision: https://reviews.llvm.org/D69656
1 parent fdd0815 commit 6773435

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

llvm/lib/Transforms/IPO/IPConstantPropagation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static bool PropagateConstantReturn(Function &F) {
254254
// Find the index of the retval to replace with
255255
int index = -1;
256256
if (ExtractValueInst *EV = dyn_cast<ExtractValueInst>(Ins))
257-
if (EV->hasIndices())
257+
if (EV->getNumIndices() == 1)
258258
index = *EV->idx_begin();
259259

260260
// If this use uses a specific return value, and we have a replacement,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -S -ipconstprop | FileCheck %s
3+
4+
%struct.wobble = type { i32 }
5+
%struct.zot = type { %struct.wobble, %struct.wobble, %struct.wobble }
6+
7+
declare dso_local fastcc float @bar(%struct.wobble* noalias, <8 x i32>) unnamed_addr
8+
9+
define %struct.zot @widget(<8 x i32> %arg) local_unnamed_addr {
10+
; CHECK-LABEL: define {{[^@]+}}@widget(
11+
; CHECK-NEXT: bb:
12+
; CHECK-NEXT: ret [[STRUCT_ZOT:%.*]] undef
13+
;
14+
bb:
15+
ret %struct.zot undef
16+
}
17+
18+
define void @baz(<8 x i32> %arg) local_unnamed_addr {
19+
; CHECK-LABEL: define {{[^@]+}}@baz(
20+
; CHECK-NEXT: bb:
21+
; CHECK-NEXT: [[TMP:%.*]] = call [[STRUCT_ZOT:%.*]] @widget(<8 x i32> [[ARG:%.*]])
22+
; CHECK-NEXT: [[TMP1:%.*]] = extractvalue [[STRUCT_ZOT]] %tmp, 0, 0
23+
; CHECK-NEXT: ret void
24+
;
25+
bb:
26+
%tmp = call %struct.zot @widget(<8 x i32> %arg)
27+
%tmp1 = extractvalue %struct.zot %tmp, 0, 0
28+
ret void
29+
}

0 commit comments

Comments
 (0)