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

Filipe Cabecinhas via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 28 14:04:14 PDT 2016


filcab added a comment.

Using undef in tests can hide some things.
Can you tell me what you get with your test case for this?

  %struct.foo = type { [1 x i64] }
  
  define <4 x i64*> @patatino3(%struct.foo*) {
    %2 = getelementptr inbounds %struct.foo, %struct.foo* %0, i32 0,
                                 i32 0, <4 x i8> zeroinitializer
    ret <4 x i64*> %2
  }

clang 3.9 gives me this:

  define <4 x i64*> @patatino3(%struct.foo* readnone) local_unnamed_addr #0 {
    %2 = getelementptr inbounds %struct.foo, %struct.foo* %0, i64 0, i32 0, <4 x i64> zeroinitializer
    ret <4 x i64*> %2
  }

Where the first i32 and the i8 vector have been cast to i64 and i64 vector.



================
Comment at: lib/Analysis/ConstantFolding.cpp:731
+             SrcElemTy, Ops.slice(1, i - 1)))) &&
+        Ops[i]->getType() != IntPtrTy && IntPtrTy->isVectorTy() &&
+        Ops[i]->getType()->getPrimitiveSizeInBits() ==
----------------
Did you mean `Ops[i]->getType()->isVectorTy()`?

From `DataLayout.h`:
    /// \brief Returns an integer type with size at least as big as that of a
    /// pointer in the given address space.
    IntegerType *getIntPtrType(LLVMContext &C, unsigned AddressSpace = 0) const;

So `IntPtrTy` will never be a vector type.
It seems with your initial patch, we're not casting at all. But I might be misunderstanding something here.


https://reviews.llvm.org/D26060





More information about the llvm-commits mailing list