[PATCH] D35956: Don't try to fold gep when the idx is a vector
Davide Italiano via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 27 15:21:31 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309330: [ConstantFolder] Don't try to fold gep when the idx is a vector. (authored by davide).
Changed prior to commit:
https://reviews.llvm.org/D35956?vs=108530&id=108531#toc
Repository:
rL LLVM
https://reviews.llvm.org/D35956
Files:
llvm/trunk/lib/IR/ConstantFold.cpp
llvm/trunk/test/Transforms/InstSimplify/pr33957.ll
Index: llvm/trunk/lib/IR/ConstantFold.cpp
===================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp
+++ llvm/trunk/lib/IR/ConstantFold.cpp
@@ -2097,15 +2097,19 @@
// Subsequent evaluation would get confused and produce erroneous results.
//
// The following prohibits such a GEP from being formed by checking to see
- // if the index is in-range with respect to an array or vector.
+ // if the index is in-range with respect to an array.
+ // TODO: This code may be extended to handle vectors as well.
bool PerformFold = false;
if (Idx0->isNullValue())
PerformFold = true;
else if (LastI.isSequential())
if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx0))
- PerformFold =
- !LastI.isBoundedSequential() ||
- isIndexInRangeOfArrayType(LastI.getSequentialNumElements(), CI);
+ PerformFold = (!LastI.isBoundedSequential() ||
+ isIndexInRangeOfArrayType(
+ LastI.getSequentialNumElements(), CI)) &&
+ !CE->getOperand(CE->getNumOperands() - 1)
+ ->getType()
+ ->isVectorTy();
if (PerformFold) {
SmallVector<Value*, 16> NewIndices;
Index: llvm/trunk/test/Transforms/InstSimplify/pr33957.ll
===================================================================
--- llvm/trunk/test/Transforms/InstSimplify/pr33957.ll
+++ llvm/trunk/test/Transforms/InstSimplify/pr33957.ll
@@ -0,0 +1,29 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -loop-unroll -S %s | FileCheck %s
+
+%struct.bar = type { i32 }
+
+ at global = external constant [78 x %struct.bar], align 4
+
+define void @patatino(i32 %x) {
+; CHECK-LABEL: @patatino(
+; CHECK-NEXT: bb:
+; CHECK-NEXT: br i1 true, label [[BB1_PREHEADER:%.*]], label [[BB3:%.*]]
+; CHECK: bb1.preheader:
+; CHECK-NEXT: br label [[BB1:%.*]]
+; CHECK: bb1:
+; CHECK-NEXT: br label [[BB3]]
+; CHECK: bb3:
+; CHECK-NEXT: ret void
+;
+bb:
+ br i1 true, label %bb1, label %bb3
+
+bb1:
+ %tmp = getelementptr inbounds [78 x %struct.bar], [78 x %struct.bar]* @global, i32 0, <4 x i32> undef
+ %tmp2 = getelementptr inbounds %struct.bar, <4 x %struct.bar*> %tmp, i32 1
+ br i1 true, label %bb3, label %bb1
+
+bb3:
+ ret void
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35956.108531.patch
Type: text/x-patch
Size: 2436 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170727/369c8972/attachment.bin>
More information about the llvm-commits
mailing list