[PATCH] D15618: [NaryReassociate] allow candidate to have a different type
Jingyue Wu via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 18 13:39:55 PST 2015
This revision was automatically updated to reflect the committed changes.
Closed by commit rL256035: [NaryReassociate] allow candidate to have a different type (authored by jingyue).
Changed prior to commit:
http://reviews.llvm.org/D15618?vs=43159&id=43262#toc
Repository:
rL LLVM
http://reviews.llvm.org/D15618
Files:
llvm/trunk/lib/Transforms/Scalar/NaryReassociate.cpp
llvm/trunk/test/Transforms/NaryReassociate/NVPTX/nary-gep.ll
Index: llvm/trunk/lib/Transforms/Scalar/NaryReassociate.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/NaryReassociate.cpp
+++ llvm/trunk/lib/Transforms/Scalar/NaryReassociate.cpp
@@ -421,19 +421,20 @@
GEP->getSourceElementType(), SE->getSCEV(GEP->getPointerOperand()),
IndexExprs, GEP->isInBounds());
- auto *Candidate = findClosestMatchingDominator(CandidateExpr, GEP);
+ Value *Candidate = findClosestMatchingDominator(CandidateExpr, GEP);
if (Candidate == nullptr)
return nullptr;
- PointerType *TypeOfCandidate = dyn_cast<PointerType>(Candidate->getType());
- // Pretty rare but theoretically possible when a numeric value happens to
- // share CandidateExpr.
- if (TypeOfCandidate == nullptr)
- return nullptr;
+ IRBuilder<> Builder(GEP);
+ // Candidate does not necessarily have the same pointer type as GEP. Use
+ // bitcast or pointer cast to make sure they have the same type, so that the
+ // later RAUW doesn't complain.
+ Candidate = Builder.CreateBitOrPointerCast(Candidate, GEP->getType());
+ assert(Candidate->getType() == GEP->getType());
// NewGEP = (char *)Candidate + RHS * sizeof(IndexedType)
uint64_t IndexedSize = DL->getTypeAllocSize(IndexedType);
- Type *ElementType = TypeOfCandidate->getElementType();
+ Type *ElementType = GEP->getType()->getElementType();
uint64_t ElementSize = DL->getTypeAllocSize(ElementType);
// Another less rare case: because I is not necessarily the last index of the
// GEP, the size of the type at the I-th index (IndexedSize) is not
@@ -453,8 +454,7 @@
return nullptr;
// NewGEP = &Candidate[RHS * (sizeof(IndexedType) / sizeof(Candidate[0])));
- IRBuilder<> Builder(GEP);
- Type *IntPtrTy = DL->getIntPtrType(TypeOfCandidate);
+ Type *IntPtrTy = DL->getIntPtrType(GEP->getType());
if (RHS->getType() != IntPtrTy)
RHS = Builder.CreateSExtOrTrunc(RHS, IntPtrTy);
if (IndexedSize != ElementSize) {
Index: llvm/trunk/test/Transforms/NaryReassociate/NVPTX/nary-gep.ll
===================================================================
--- llvm/trunk/test/Transforms/NaryReassociate/NVPTX/nary-gep.ll
+++ llvm/trunk/test/Transforms/NaryReassociate/NVPTX/nary-gep.ll
@@ -123,4 +123,21 @@
ret void
}
+%struct.complex = type { float, float }
+
+declare void @bar(%struct.complex*)
+
+define void @different_types(%struct.complex* %input, i64 %i) {
+; CHECK-LABEL: @different_types(
+ %t1 = getelementptr %struct.complex, %struct.complex* %input, i64 %i
+ call void @bar(%struct.complex* %t1)
+ %j = add i64 %i, 5
+ %t2 = getelementptr %struct.complex, %struct.complex* %input, i64 %j, i32 0
+; CHECK: [[cast:[^ ]+]] = bitcast %struct.complex* %t1 to float*
+; CHECK-NEXT: %t2 = getelementptr float, float* [[cast]], i64 10
+; CHECK-NEXT: call void @foo(float* %t2)
+ call void @foo(float* %t2)
+ ret void
+}
+
declare void @llvm.assume(i1)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15618.43262.patch
Type: text/x-patch
Size: 2948 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151218/117ad788/attachment.bin>
More information about the llvm-commits
mailing list