[PATCH] [InstSimplify] Support constant folding to vector of pointers
Matt Arsenault
Matthew.Arsenault at amd.com
Fri Oct 17 11:44:33 PDT 2014
================
Comment at: lib/Analysis/ConstantFolding.cpp:59
@@ -59,1 +58,3 @@
+ if (C->isAllOnesValue() && !DestTy->isX86_MMXTy() &&
+ !DestTy->isPtrOrPtrVectorTy()) // don't get ones for ptr types!
return Constant::getAllOnesValue(DestTy);
----------------
Comment should be capitalized.
Why do you need this check on the isAllOnesValue() and not the isNullValue() case?
================
Comment at: lib/Analysis/ConstantFolding.cpp:200
@@ +199,3 @@
+ // Handle: bitcast (<2 x i64> <i64 0, i64 1> to <4 x i32>) and
+ // bitcast (<1 x i128> <i128 -1> to <2 x i8*>)
+ bool IsDstEltTyPtr = DstEltTy->isPointerTy();
----------------
Slightly misleading comment? This bitcast isn't allowed and this needs to be an inttoptr
================
Comment at: lib/Analysis/ConstantFolding.cpp:203-204
@@ -199,3 +202,4 @@
unsigned Ratio = NumDstElt/NumSrcElt;
- unsigned DstBitSize = DstEltTy->getPrimitiveSizeInBits();
+ unsigned DstBitSize = IsDstEltTyPtr ? TD.getPointerTypeSizeInBits(DstEltTy)
+ : DstEltTy->getPrimitiveSizeInBits();
----------------
You don't need to do this check to get the type size yourself. TD.getTypeSizeInBits checks the pointeriness for you
================
Comment at: test/Transforms/InstSimplify/vector_ptr_bitcast.ll:6-8
@@ +5,5 @@
+
+ at a = private unnamed_addr constant %mst { i8* inttoptr (i64 -1 to i8*),
+ i8* inttoptr (i64 -1 to i8*)},
+ align 8
+
----------------
Another testcase that uses different sized pointers that require a trunc might be useful. Also one that uses constants other than -1
================
Comment at: test/Transforms/InstSimplify/vector_ptr_bitcast.ll:12-13
@@ +11,4 @@
+ %x = load <2 x i8*>* bitcast (%mst* @a to <2 x i8*>*), align 8
+ %b = extractelement <2 x i8*> %x, i32 0
+ ; CHECK-LABEL: @fn
+ ; CHECK-NEXT: ret void
----------------
Test should probably do something with this so there is something to check other than deleting all of the code
http://reviews.llvm.org/D5834
More information about the llvm-commits
mailing list