[llvm] 6773435 - [IPCP] Bail on extractvalue's with more than 1 index.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 31 10:56:08 PDT 2019
Author: Craig Topper
Date: 2019-10-31T10:55:20-07:00
New Revision: 6773435624288f9c69d7ae4b804f2410808cf1a2
URL: https://github.com/llvm/llvm-project/commit/6773435624288f9c69d7ae4b804f2410808cf1a2
DIFF: https://github.com/llvm/llvm-project/commit/6773435624288f9c69d7ae4b804f2410808cf1a2.diff
LOG: [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
Added:
llvm/test/Transforms/IPConstantProp/PR43857.ll
Modified:
llvm/lib/Transforms/IPO/IPConstantPropagation.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp b/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp
index 7dc4d9ee9e34..7cbeb4b7cbbd 100644
--- a/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp
+++ b/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp
@@ -254,7 +254,7 @@ static bool PropagateConstantReturn(Function &F) {
// Find the index of the retval to replace with
int index = -1;
if (ExtractValueInst *EV = dyn_cast<ExtractValueInst>(Ins))
- if (EV->hasIndices())
+ if (EV->getNumIndices() == 1)
index = *EV->idx_begin();
// If this use uses a specific return value, and we have a replacement,
diff --git a/llvm/test/Transforms/IPConstantProp/PR43857.ll b/llvm/test/Transforms/IPConstantProp/PR43857.ll
new file mode 100644
index 000000000000..d098d552b3fc
--- /dev/null
+++ b/llvm/test/Transforms/IPConstantProp/PR43857.ll
@@ -0,0 +1,29 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -S -ipconstprop | FileCheck %s
+
+%struct.wobble = type { i32 }
+%struct.zot = type { %struct.wobble, %struct.wobble, %struct.wobble }
+
+declare dso_local fastcc float @bar(%struct.wobble* noalias, <8 x i32>) unnamed_addr
+
+define %struct.zot @widget(<8 x i32> %arg) local_unnamed_addr {
+; CHECK-LABEL: define {{[^@]+}}@widget(
+; CHECK-NEXT: bb:
+; CHECK-NEXT: ret [[STRUCT_ZOT:%.*]] undef
+;
+bb:
+ ret %struct.zot undef
+}
+
+define void @baz(<8 x i32> %arg) local_unnamed_addr {
+; CHECK-LABEL: define {{[^@]+}}@baz(
+; CHECK-NEXT: bb:
+; CHECK-NEXT: [[TMP:%.*]] = call [[STRUCT_ZOT:%.*]] @widget(<8 x i32> [[ARG:%.*]])
+; CHECK-NEXT: [[TMP1:%.*]] = extractvalue [[STRUCT_ZOT]] %tmp, 0, 0
+; CHECK-NEXT: ret void
+;
+bb:
+ %tmp = call %struct.zot @widget(<8 x i32> %arg)
+ %tmp1 = extractvalue %struct.zot %tmp, 0, 0
+ ret void
+}
More information about the llvm-commits
mailing list