[llvm] r315044 - Roll forward r314928
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 5 22:15:25 PDT 2017
Author: davidxl
Date: Thu Oct 5 22:15:25 2017
New Revision: 315044
URL: http://llvm.org/viewvc/llvm-project?rev=315044&view=rev
Log:
Roll forward r314928
Fixed ThinLTO bootstrap failure : track new
bitcast per incomingVal. Added new tests.
Added:
llvm/trunk/test/Transforms/InstCombine/intptr1.ll
- copied, changed from r314960, llvm/trunk/test/Transforms/InstCombine/intptr1.ll
llvm/trunk/test/Transforms/InstCombine/intptr2.ll
- copied, changed from r314960, llvm/trunk/test/Transforms/InstCombine/intptr2.ll
llvm/trunk/test/Transforms/InstCombine/intptr3.ll
- copied, changed from r314960, llvm/trunk/test/Transforms/InstCombine/intptr3.ll
llvm/trunk/test/Transforms/InstCombine/intptr4.ll
- copied, changed from r314960, llvm/trunk/test/Transforms/InstCombine/intptr4.ll
llvm/trunk/test/Transforms/InstCombine/intptr5.ll
llvm/trunk/test/Transforms/InstCombine/intptr6.ll
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h?rev=315044&r1=315043&r2=315044&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h Thu Oct 5 22:15:25 2017
@@ -670,6 +670,10 @@ private:
Instruction *FoldPHIArgGEPIntoPHI(PHINode &PN);
Instruction *FoldPHIArgLoadIntoPHI(PHINode &PN);
Instruction *FoldPHIArgZextsIntoPHI(PHINode &PN);
+ /// If an integer typed PHI has only one use which is an IntToPtr operation,
+ /// replace the PHI with an existing pointer typed PHI if it exists. Otherwise
+ /// insert a new pointer typed PHI and replace the original one.
+ Instruction *FoldIntegerTypedPHI(PHINode &PN);
/// Helper function for FoldPHIArgXIntoPHI() to set debug location for the
/// folded operation.
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp?rev=315044&r1=315043&r2=315044&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp Thu Oct 5 22:15:25 2017
@@ -40,6 +40,237 @@ void InstCombiner::PHIArgMergedDebugLoc(
}
}
+// Replace Integer typed PHI PN if the PHI's value is used as a pointer value.
+// If there is an existing pointer typed PHI that produces the same value as PN,
+// replace PN and the IntToPtr operation with it. Otherwise, synthesize a new
+// PHI node:
+//
+// Case-1:
+// bb1:
+// int_init = PtrToInt(ptr_init)
+// br label %bb2
+// bb2:
+// int_val = PHI([int_init, %bb1], [int_val_inc, %bb2]
+// ptr_val = PHI([ptr_init, %bb1], [ptr_val_inc, %bb2]
+// ptr_val2 = IntToPtr(int_val)
+// ...
+// use(ptr_val2)
+// ptr_val_inc = ...
+// inc_val_inc = PtrToInt(ptr_val_inc)
+//
+// ==>
+// bb1:
+// br label %bb2
+// bb2:
+// ptr_val = PHI([ptr_init, %bb1], [ptr_val_inc, %bb2]
+// ...
+// use(ptr_val)
+// ptr_val_inc = ...
+//
+// Case-2:
+// bb1:
+// int_ptr = BitCast(ptr_ptr)
+// int_init = Load(int_ptr)
+// br label %bb2
+// bb2:
+// int_val = PHI([int_init, %bb1], [int_val_inc, %bb2]
+// ptr_val2 = IntToPtr(int_val)
+// ...
+// use(ptr_val2)
+// ptr_val_inc = ...
+// inc_val_inc = PtrToInt(ptr_val_inc)
+// ==>
+// bb1:
+// ptr_init = Load(ptr_ptr)
+// br label %bb2
+// bb2:
+// ptr_val = PHI([ptr_init, %bb1], [ptr_val_inc, %bb2]
+// ...
+// use(ptr_val)
+// ptr_val_inc = ...
+// ...
+//
+Instruction *InstCombiner::FoldIntegerTypedPHI(PHINode &PN) {
+ if (!PN.getType()->isIntegerTy())
+ return nullptr;
+ if (!PN.hasOneUse())
+ return nullptr;
+
+ auto *IntToPtr = dyn_cast<IntToPtrInst>(PN.user_back());
+ if (!IntToPtr)
+ return nullptr;
+
+ // Check if the pointer is actually used as pointer:
+ auto HasPointerUse = [](Instruction *IIP) {
+ for (User *U : IIP->users()) {
+ Value *Ptr = nullptr;
+ if (LoadInst *LoadI = dyn_cast<LoadInst>(U)) {
+ Ptr = LoadI->getPointerOperand();
+ } else if (StoreInst *SI = dyn_cast<StoreInst>(U)) {
+ Ptr = SI->getPointerOperand();
+ } else if (GetElementPtrInst *GI = dyn_cast<GetElementPtrInst>(U)) {
+ Ptr = GI->getPointerOperand();
+ }
+
+ if (Ptr && Ptr == IIP)
+ return true;
+ }
+ return false;
+ };
+
+ if (!HasPointerUse(IntToPtr))
+ return nullptr;
+
+ if (DL.getPointerSizeInBits(IntToPtr->getAddressSpace()) !=
+ DL.getTypeSizeInBits(IntToPtr->getOperand(0)->getType()))
+ return nullptr;
+
+ SmallVector<Value *, 4> AvailablePtrVals;
+ for (unsigned i = 0; i != PN.getNumIncomingValues(); ++i) {
+ Value *Arg = PN.getIncomingValue(i);
+
+ // First look backward:
+ if (auto *PI = dyn_cast<PtrToIntInst>(Arg)) {
+ AvailablePtrVals.emplace_back(PI->getOperand(0));
+ continue;
+ }
+
+ // Next look forward:
+ Value *ArgIntToPtr = nullptr;
+ for (User *U : Arg->users()) {
+ if (isa<IntToPtrInst>(U) && U->getType() == IntToPtr->getType() &&
+ (DT.dominates(cast<Instruction>(U), PN.getIncomingBlock(i)) ||
+ cast<Instruction>(U)->getParent() == PN.getIncomingBlock(i))) {
+ ArgIntToPtr = U;
+ break;
+ }
+ }
+
+ if (ArgIntToPtr) {
+ AvailablePtrVals.emplace_back(ArgIntToPtr);
+ continue;
+ }
+
+ // If Arg is defined by a PHI, allow it. This will also create
+ // more opportunities iteratively.
+ if (isa<PHINode>(Arg)) {
+ AvailablePtrVals.emplace_back(Arg);
+ continue;
+ }
+
+ // For a single use integer load:
+ auto *LoadI = dyn_cast<LoadInst>(Arg);
+ if (!LoadI)
+ return nullptr;
+
+ if (!LoadI->hasOneUse())
+ return nullptr;
+
+ // Push the integer typed Load instruction into the available
+ // value set, and fix it up later when the pointer typed PHI
+ // is synthesized.
+ AvailablePtrVals.emplace_back(LoadI);
+ }
+
+ // Now search for a matching PHI
+ auto *BB = PN.getParent();
+ assert(AvailablePtrVals.size() == PN.getNumIncomingValues() &&
+ "Not enough available ptr typed incoming values");
+ PHINode *MatchingPtrPHI = nullptr;
+ for (auto II = BB->begin(), EI = BasicBlock::iterator(BB->getFirstNonPHI());
+ II != EI; II++) {
+ PHINode *PtrPHI = dyn_cast<PHINode>(II);
+ if (!PtrPHI || PtrPHI == &PN || PtrPHI->getType() != IntToPtr->getType())
+ continue;
+ MatchingPtrPHI = PtrPHI;
+ for (unsigned i = 0; i != PtrPHI->getNumIncomingValues(); ++i) {
+ if (AvailablePtrVals[i] != PtrPHI->getIncomingValue(i)) {
+ MatchingPtrPHI = nullptr;
+ break;
+ }
+ }
+
+ if (MatchingPtrPHI)
+ break;
+ }
+
+ if (MatchingPtrPHI) {
+ assert(MatchingPtrPHI->getType() == IntToPtr->getType() &&
+ "Phi's Type does not match with IntToPtr");
+ // The PtrToCast + IntToPtr will be simplified later
+ return CastInst::CreateBitOrPointerCast(MatchingPtrPHI,
+ IntToPtr->getOperand(0)->getType());
+ }
+
+ // If it requires a conversion for every PHI operand, do not do it.
+ if (std::all_of(AvailablePtrVals.begin(), AvailablePtrVals.end(),
+ [&](Value *V) {
+ return (V->getType() != IntToPtr->getType()) ||
+ isa<IntToPtrInst>(V);
+ }))
+ return nullptr;
+
+ // If any of the operand that requires casting is a terminator
+ // instruction, do not do it.
+ if (std::any_of(AvailablePtrVals.begin(), AvailablePtrVals.end(),
+ [&](Value *V) {
+ return (V->getType() != IntToPtr->getType()) &&
+ isa<TerminatorInst>(V);
+ }))
+ return nullptr;
+
+ PHINode *NewPtrPHI = PHINode::Create(
+ IntToPtr->getType(), PN.getNumIncomingValues(), PN.getName() + ".ptr");
+
+ InsertNewInstBefore(NewPtrPHI, PN);
+ SmallDenseMap<Value *, Instruction *> Casts;
+ for (unsigned i = 0; i != PN.getNumIncomingValues(); ++i) {
+ auto *IncomingBB = PN.getIncomingBlock(i);
+ auto *IncomingVal = AvailablePtrVals[i];
+
+ if (IncomingVal->getType() == IntToPtr->getType()) {
+ NewPtrPHI->addIncoming(IncomingVal, IncomingBB);
+ continue;
+ }
+
+#ifndef NDEBUG
+ LoadInst *LoadI = dyn_cast<LoadInst>(IncomingVal);
+ assert((isa<PHINode>(IncomingVal) ||
+ IncomingVal->getType()->isPointerTy() ||
+ (LoadI && LoadI->hasOneUse())) &&
+ "Can not replace LoadInst with multiple uses");
+#endif
+ // Need to insert a BitCast.
+ // For an integer Load instruction with a single use, the load + IntToPtr
+ // cast will be simplified into a pointer load:
+ // %v = load i64, i64* %a.ip, align 8
+ // %v.cast = inttoptr i64 %v to float **
+ // ==>
+ // %v.ptrp = bitcast i64 * %a.ip to float **
+ // %v.cast = load float *, float ** %v.ptrp, align 8
+ Instruction *&CI = Casts[IncomingVal];
+ if (!CI) {
+ CI = CastInst::CreateBitOrPointerCast(
+ IncomingVal, IntToPtr->getType(), IncomingVal->getName() + ".ptr");
+ if (auto *IncomingI = dyn_cast<Instruction>(IncomingVal)) {
+ BasicBlock::iterator InsertPos(IncomingI);
+ InsertPos++;
+ if (isa<PHINode>(IncomingI))
+ InsertPos = IncomingI->getParent()->getFirstInsertionPt();
+ InsertNewInstBefore(CI, *InsertPos);
+ } else {
+ auto *InsertBB = &IncomingBB->getParent()->getEntryBlock();
+ InsertNewInstBefore(CI, *InsertBB->getFirstInsertionPt());
+ }
+ }
+ NewPtrPHI->addIncoming(CI, IncomingBB);
+ }
+
+ // The PtrToCast + IntToPtr will be simplified later
+ return CastInst::CreateBitOrPointerCast(NewPtrPHI,
+ IntToPtr->getOperand(0)->getType());
+}
+
/// If we have something like phi [add (a,b), add(a,c)] and if a/b/c and the
/// adds all have a single use, turn this into a phi and a single binop.
Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) {
@@ -903,6 +1134,9 @@ Instruction *InstCombiner::visitPHINode(
// this PHI only has a single use (a PHI), and if that PHI only has one use (a
// PHI)... break the cycle.
if (PN.hasOneUse()) {
+ if (Instruction *Result = FoldIntegerTypedPHI(PN))
+ return Result;
+
Instruction *PHIUser = cast<Instruction>(PN.user_back());
if (PHINode *PU = dyn_cast<PHINode>(PHIUser)) {
SmallPtrSet<PHINode*, 16> PotentiallyDeadPHIs;
Copied: llvm/trunk/test/Transforms/InstCombine/intptr1.ll (from r314960, llvm/trunk/test/Transforms/InstCombine/intptr1.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/intptr1.ll?p2=llvm/trunk/test/Transforms/InstCombine/intptr1.ll&p1=llvm/trunk/test/Transforms/InstCombine/intptr1.ll&r1=314960&r2=315044&rev=315044&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/intptr1.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/intptr1.ll Thu Oct 5 22:15:25 2017
@@ -1,6 +1,5 @@
; RUN: opt < %s -instcombine -S | FileCheck %s
-
define void @test1(float* %a, float* readnone %a_end, i64* %b.i64) {
; CHECK-LABEL: @test1
entry:
@@ -23,12 +22,15 @@ for.body:
%tmp = inttoptr i64 %b.addr.02 to float*
; CHECK-NOT: inttoptr i64
%tmp1 = load float, float* %tmp, align 4
+; CHECK: = load
%mul.i = fmul float %tmp1, 4.200000e+01
store float %mul.i, float* %a.addr.03, align 4
%add = getelementptr inbounds float, float* %tmp, i64 1
%add.int = ptrtoint float* %add to i64
+; CHECK %add = getelementptr
; CHECK-NOT: ptrtoint float*
%incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
+; CHECK: %incdec.ptr =
%cmp = icmp ult float* %incdec.ptr, %a_end
br i1 %cmp, label %for.body, label %for.end
@@ -97,12 +99,15 @@ for.body:
%tmp = inttoptr i64 %b.addr.02 to float*
; CHECK-NOT: inttoptr i64
%tmp1 = load float, float* %tmp, align 4
+; CHECK: = load
%mul.i = fmul float %tmp1, 4.200000e+01
store float %mul.i, float* %a.addr.03, align 4
%add = getelementptr inbounds float, float* %tmp, i64 1
+; CHECK: %add =
%add.int = ptrtoint float* %add to i64
; CHECK-NOT: ptrtoint float*
%incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
+; CHECK: %incdec.ptr =
%cmp = icmp ult float* %incdec.ptr, %a_end
br i1 %cmp, label %for.body, label %for.end
@@ -134,12 +139,15 @@ for.body:
%tmp = inttoptr i64 %b.addr.02 to float*
; CHECK-NOT: inttoptr i64
%tmp1 = load float, float* %tmp, align 4
+; CHECK: = load
%mul.i = fmul float %tmp1, 4.200000e+01
store float %mul.i, float* %a.addr.03, align 4
%add = getelementptr inbounds float, float* %tmp, i64 1
+; CHECK: %add = getelementptr
%add.int = ptrtoint float* %add to i64
; CHECK-NOT: ptrtoint float*
%incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
+; CHECK: %incdec.ptr =
%cmp = icmp ult float* %incdec.ptr, %a_end
br i1 %cmp, label %for.body, label %for.end
@@ -160,6 +168,7 @@ for.body.preheader:
; CHECK: load float*, float**
; CHECK-NOT: ptrtoint float*
br label %for.body
+; CHECK: br label %for.body
for.body: ; preds = %for.body, %for.body.preheader
%a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
@@ -167,12 +176,15 @@ for.body:
%tmp = inttoptr i64 %b.addr.02 to float*
; CHECK-NOT: inttoptr i64
%tmp1 = load float, float* %tmp, align 4
+; CHECK: = load
%mul.i = fmul float %tmp1, 4.200000e+01
store float %mul.i, float* %a.addr.03, align 4
%add = getelementptr inbounds float, float* %tmp, i64 1
+; CHECK: %add =
%add.int = ptrtoint float* %add to i64
; CHECK-NOT: ptrtoint float*
%incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
+; CHECK: %incdec.ptr =
%cmp = icmp ult float* %incdec.ptr, %a_end
br i1 %cmp, label %for.body, label %for.end
Copied: llvm/trunk/test/Transforms/InstCombine/intptr2.ll (from r314960, llvm/trunk/test/Transforms/InstCombine/intptr2.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/intptr2.ll?p2=llvm/trunk/test/Transforms/InstCombine/intptr2.ll&p1=llvm/trunk/test/Transforms/InstCombine/intptr2.ll&r1=314960&r2=315044&rev=315044&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/intptr2.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/intptr2.ll Thu Oct 5 22:15:25 2017
@@ -11,23 +11,25 @@ for.body.preheader:
; CHECK: bitcast
; CHECK-NOT: ptrtoint
br label %for.body
+; CHECK: br label %for.body
for.body: ; preds = %for.body, %for.body.preheader
%a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
%b.addr.02 = phi i64 [ %add.int, %for.body ], [ %b, %for.body.preheader ]
-
; CHECK: %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
; CHECK-NOT: phi i64
-
%tmp = inttoptr i64 %b.addr.02 to float*
; CHECK-NOT: inttoptr
%tmp1 = load float, float* %tmp, align 4
+; CHECK: = load
%mul.i = fmul float %tmp1, 4.200000e+01
store float %mul.i, float* %a.addr.03, align 4
%add = getelementptr inbounds float, float* %tmp, i64 1
+; CHECK: %add =
%add.int = ptrtoint float* %add to i64
; CHECK-NOT: ptrtoint
%incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
+; CHECK: %incdec.ptr =
%cmp = icmp ult float* %incdec.ptr, %a_end
br i1 %cmp, label %for.body, label %for.end
Copied: llvm/trunk/test/Transforms/InstCombine/intptr3.ll (from r314960, llvm/trunk/test/Transforms/InstCombine/intptr3.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/intptr3.ll?p2=llvm/trunk/test/Transforms/InstCombine/intptr3.ll&p1=llvm/trunk/test/Transforms/InstCombine/intptr3.ll&r1=314960&r2=315044&rev=315044&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/intptr3.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/intptr3.ll Thu Oct 5 22:15:25 2017
@@ -1,6 +1,5 @@
; RUN: opt < %s -instcombine -S | FileCheck %s
-
define void @test(float* %a, float* readnone %a_end, i64 %b) unnamed_addr {
entry:
%cmp1 = icmp ult float* %a, %a_end
@@ -20,12 +19,15 @@ for.body:
%l = load float, float* %b.addr.float, align 4
%mul.i = fmul float %l, 4.200000e+01
store float %mul.i, float* %a.addr.03, align 4
+; CHECK: store float
%b.addr.float.2 = inttoptr i64 %b.addr.i64 to float*
; CHECK-NOT: inttoptr
%b.addr.float.inc = getelementptr inbounds float, float* %b.addr.float.2, i64 1
+; CHECK: %b.addr.float.inc =
%b.addr.i64.inc = ptrtoint float* %b.addr.float.inc to i64
; CHECK-NOT: ptrtoint
%incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
+; CHECK: %incdec.ptr =
%cmp = icmp ult float* %incdec.ptr, %a_end
br i1 %cmp, label %for.body, label %for.end
Copied: llvm/trunk/test/Transforms/InstCombine/intptr4.ll (from r314960, llvm/trunk/test/Transforms/InstCombine/intptr4.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/intptr4.ll?p2=llvm/trunk/test/Transforms/InstCombine/intptr4.ll&p1=llvm/trunk/test/Transforms/InstCombine/intptr4.ll&r1=314960&r2=315044&rev=315044&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/intptr4.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/intptr4.ll Thu Oct 5 22:15:25 2017
@@ -1,6 +1,5 @@
; RUN: opt < %s -instcombine -S | FileCheck %s
-
define void @test(float* %a, float* readnone %a_end, i64 %b, float* %bf) unnamed_addr {
entry:
%cmp1 = icmp ult float* %a, %a_end
@@ -15,27 +14,34 @@ bb2:
for.body.preheader: ; preds = %entry
%b.phi = phi i64 [%b, %bb1], [%bfi, %bb2]
-; CHECK-LABEL: for.body.preheader
-; CHECK-NOT: %b.phi = phi i64
br label %for.body
+; CHECK: for.body.preheader
+; CHECK: %b.phi = phi
+; CHECK: %b.phi.ptr =
+; CHECK: br label %for.body
for.body: ; preds = %for.body.preheader, %for.body
-; CHECK-LABEL: for.body
+; CHECK: for.body
%a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
%b.addr.float = phi float* [ %b.addr.float.inc, %for.body ], [ %b.float, %for.body.preheader ]
%b.addr.i64 = phi i64 [ %b.addr.i64.inc, %for.body ], [ %b.phi, %for.body.preheader ]
; CHECK: %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
-; CHECK-NEXT: %b.addr.float = phi float* [ %b.addr.float.inc, %for.body ], [ %b.float, %for.body.preheader ]
-; CHECK-NOT: = %b.addr.i64
+; CHECK-NEXT: %b.addr.float = phi float* [ %b.addr.float.inc, %for.body ], [ %b.float, %for.body.preheader ]
+; CHECK-NEXT: %b.addr.i64.ptr = phi
+; CHECK-NOT: = phi i64
+; CHECK: = load
%l = load float, float* %b.addr.float, align 4
%mul.i = fmul float %l, 4.200000e+01
store float %mul.i, float* %a.addr.03, align 4
%b.addr.float.2 = inttoptr i64 %b.addr.i64 to float*
-; CHECK-NOT: inttoptr
%b.addr.float.inc = getelementptr inbounds float, float* %b.addr.float.2, i64 1
+; CHECK: store float %mul.i
+; CHECK-NOT: inttoptr
+; CHECK: %b.addr.float.inc =
%b.addr.i64.inc = ptrtoint float* %b.addr.float.inc to i64
; CHECK-NOT: ptrtoint
%incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
+; CHECK: %incdec.ptr =
%cmp = icmp ult float* %incdec.ptr, %a_end
br i1 %cmp, label %for.body, label %for.end
Added: llvm/trunk/test/Transforms/InstCombine/intptr5.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/intptr5.ll?rev=315044&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/intptr5.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/intptr5.ll Thu Oct 5 22:15:25 2017
@@ -0,0 +1,56 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define void @test(float* %a, float* readnone %a_end, i64 %b, float* %bf) unnamed_addr {
+entry:
+ %cmp1 = icmp ult float* %a, %a_end
+ %b.float = inttoptr i64 %b to float*
+ br i1 %cmp1, label %bb1, label %bb2
+
+bb1:
+ br label %for.body.preheader
+bb2:
+ %bfi = ptrtoint float* %bf to i64
+ br label %for.body.preheader
+
+for.body.preheader: ; preds = %entry
+ %b.phi = phi i64 [%b, %bb1], [%bfi, %bb2]
+ switch i64 %b, label %for.body [
+ i64 1, label %for.body
+ ]
+; CHECK: for.body.preheader
+; CHECK: %b.phi = phi
+; CHECK: %b.phi.ptr =
+; CHECK-NOT: %b.phi.ptr2 =
+; CHECK: switch
+
+for.body: ; preds = %for.body.preheader, %for.body
+; CHECK: for.body
+ %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ], [%a, %for.body.preheader]
+ %b.addr.float = phi float* [ %b.addr.float.inc, %for.body ], [ %b.float, %for.body.preheader ], [%b.float, %for.body.preheader]
+ %b.addr.i64 = phi i64 [ %b.addr.i64.inc, %for.body ], [ %b.phi, %for.body.preheader ], [ %b.phi, %for.body.preheader]
+; CHECK: %a.addr.03 = phi float* [ %incdec.ptr, %for.body ], [ %a, %for.body.preheader ]
+; CHECK-NEXT: %b.addr.float = phi float* [ %b.addr.float.inc, %for.body ], [ %b.float, %for.body.preheader ]
+; CHECK-NEXT: %b.addr.i64.ptr = phi
+; CHECK-NOT: = %b.addr.i64
+; CHECK: = load
+ %l = load float, float* %b.addr.float, align 4
+ %mul.i = fmul float %l, 4.200000e+01
+ store float %mul.i, float* %a.addr.03, align 4
+ %b.addr.float.2 = inttoptr i64 %b.addr.i64 to float*
+ %b.addr.float.inc = getelementptr inbounds float, float* %b.addr.float.2, i64 1
+; CHECK: store float %mul.i
+; CHECK-NOT: inttoptr
+; CHECK: %b.addr.float.inc =
+ %b.addr.i64.inc = ptrtoint float* %b.addr.float.inc to i64
+; CHECK-NOT: ptrtoint
+ %incdec.ptr = getelementptr inbounds float, float* %a.addr.03, i64 1
+; CHECK: %incdec.ptr =
+ %cmp = icmp ult float* %incdec.ptr, %a_end
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %for.body, %entry
+ ret void
+}
+
+
+
Added: llvm/trunk/test/Transforms/InstCombine/intptr6.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/intptr6.ll?rev=315044&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/intptr6.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/intptr6.ll Thu Oct 5 22:15:25 2017
@@ -0,0 +1,90 @@
+; RUN: opt < %s -instcombine -S
+; no crash
+
+%A = type { %B }
+%B = type { %C *}
+%C = type <{ i32 (...)**, i32, [4 x i8] }>
+
+$foo = comdat any
+
+ at bar= external thread_local global %A, align 8
+
+declare i32 @__gxx_personality_v0(...)
+
+; Function Attrs: inlinehint sanitize_memory uwtable
+define void @foo() local_unnamed_addr #0 comdat align 2 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+entry:
+ %0 = load %C*, %C** getelementptr inbounds (%A, %A* @bar, i64 0, i32 0, i32 0), align 8
+ %1 = ptrtoint %C* %0 to i64
+ %count.i.i.i23 = getelementptr inbounds %C, %C* %0, i64 0, i32 1
+ store i32 0, i32* %count.i.i.i23, align 8
+ %2 = invoke i8* @_Znwm() #3
+ to label %invoke.cont unwind label %lpad
+
+invoke.cont: ; preds = %entry
+ %call.i25 = invoke i8* @_Znwm() #3
+ to label %call.i.noexc unwind label %lpad4
+
+call.i.noexc: ; preds = %invoke.cont
+ invoke void @lazy()
+ to label %invoke.cont5 unwind label %lpad.i
+
+lpad.i: ; preds = %call.i.noexc
+ %3 = landingpad { i8*, i32 }
+ cleanup
+ br label %ehcleanup
+
+invoke.cont5: ; preds = %call.i.noexc
+ %4 = ptrtoint i8* %call.i25 to i64
+ invoke void @scale()
+ to label %invoke.cont16 unwind label %lpad15
+
+invoke.cont16: ; preds = %invoke.cont5
+ ret void
+
+lpad: ; preds = %entry
+ %5 = landingpad { i8*, i32 }
+ cleanup
+ unreachable
+
+lpad4: ; preds = %invoke.cont
+ %6 = landingpad { i8*, i32 }
+ cleanup
+ unreachable
+
+ehcleanup: ; preds = %lpad.i
+ br label %ehcleanup21
+
+lpad15: ; preds = %invoke.cont5
+ %7 = landingpad { i8*, i32 }
+ cleanup
+ br label %ehcleanup21
+
+ehcleanup21: ; preds = %lpad15, %ehcleanup
+ %actual_other.sroa.0.0 = phi i64 [ %1, %ehcleanup ], [ %4, %lpad15 ]
+ %8 = inttoptr i64 %actual_other.sroa.0.0 to %C*
+ br i1 undef, label %_ZN4CGAL6HandleD2Ev.exit, label %land.lhs.true.i
+
+land.lhs.true.i: ; preds = %ehcleanup21
+ %count.i = getelementptr inbounds %C, %C* %8, i64 0, i32 1
+ %9 = load i32, i32* %count.i, align 8
+ unreachable
+
+_ZN4CGAL6HandleD2Ev.exit: ; preds = %ehcleanup21
+ resume { i8*, i32 } undef
+}
+
+; Function Attrs: nobuiltin
+declare noalias nonnull i8* @_Znwm() local_unnamed_addr #1
+
+; Function Attrs: sanitize_memory uwtable
+declare void @scale() local_unnamed_addr #2 align 2
+
+; Function Attrs: sanitize_memory uwtable
+declare void @lazy() unnamed_addr #2 align 2
+
+attributes #0 = { inlinehint sanitize_memory uwtable}
+attributes #1 = { nobuiltin }
+attributes #2 = { sanitize_memory uwtable }
+attributes #3 = { builtin }
+
More information about the llvm-commits
mailing list