[PATCH] D26060: [ConstantFolding] Don't try to cast vectors to pointer if they have different size

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 28 15:58:41 PDT 2016


davide updated this revision to Diff 76267.
davide added a comment.

On a second thought, the check for the size should be enough in this case.


https://reviews.llvm.org/D26060

Files:
  lib/Analysis/ConstantFolding.cpp
  test/Transforms/InstCombine/gep-vector.ll


Index: test/Transforms/InstCombine/gep-vector.ll
===================================================================
--- test/Transforms/InstCombine/gep-vector.ll
+++ test/Transforms/InstCombine/gep-vector.ll
@@ -13,3 +13,13 @@
   %el = getelementptr inbounds i64, i64* undef, <8 x i64> undef
   ret <8 x i64*> %el
 }
+
+%struct.foo = type { [0 x i64] }
+
+; CHECK-LABEL: patatino3
+; CHECK-NEXT: ret <8 x i64*> undef
+define <8 x i64*> @patatino3(%struct.foo*) {
+  %2 = getelementptr inbounds %struct.foo, %struct.foo* undef, i64 0,
+                               i32 0, <8 x i64> undef
+  ret <8 x i64*> %2
+}
Index: lib/Analysis/ConstantFolding.cpp
===================================================================
--- lib/Analysis/ConstantFolding.cpp
+++ lib/Analysis/ConstantFolding.cpp
@@ -726,9 +726,11 @@
   SmallVector<Constant*, 32> NewIdxs;
   for (unsigned i = 1, e = Ops.size(); i != e; ++i) {
     if ((i == 1 ||
-         !isa<StructType>(GetElementPtrInst::getIndexedType(SrcElemTy,
-             Ops.slice(1, i - 1)))) &&
-        Ops[i]->getType() != IntPtrTy) {
+         !isa<StructType>(GetElementPtrInst::getIndexedType(
+             SrcElemTy, Ops.slice(1, i - 1)))) &&
+        Ops[i]->getType() != IntPtrTy &&
+        Ops[i]->getType()->getPrimitiveSizeInBits() ==
+            IntPtrTy->getPrimitiveSizeInBits()) {
       Any = true;
       NewIdxs.push_back(ConstantExpr::getCast(CastInst::getCastOpcode(Ops[i],
                                                                       true,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26060.76267.patch
Type: text/x-patch
Size: 1522 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161028/aa2d6efb/attachment.bin>


More information about the llvm-commits mailing list