mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
SROA: Don't insert instructions before a PHI
SROA may decide that it needs to insert a bitcast and would set it's insertion point before a PHI. This will create an invalid module right quick. Instead, choose the first insertion point in the basic block that holds our PHI. This fixes PR20822. Differential Revision: http://reviews.llvm.org/D5141 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216891 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -2708,7 +2708,10 @@ private:
|
|||||||
// the old pointer, which necessarily must be in the right position to
|
// the old pointer, which necessarily must be in the right position to
|
||||||
// dominate the PHI.
|
// dominate the PHI.
|
||||||
IRBuilderTy PtrBuilder(IRB);
|
IRBuilderTy PtrBuilder(IRB);
|
||||||
PtrBuilder.SetInsertPoint(OldPtr);
|
if (isa<PHINode>(OldPtr))
|
||||||
|
PtrBuilder.SetInsertPoint(OldPtr->getParent()->getFirstInsertionPt());
|
||||||
|
else
|
||||||
|
PtrBuilder.SetInsertPoint(OldPtr);
|
||||||
PtrBuilder.SetCurrentDebugLocation(OldPtr->getDebugLoc());
|
PtrBuilder.SetCurrentDebugLocation(OldPtr->getDebugLoc());
|
||||||
|
|
||||||
Value *NewPtr = getNewAllocaSlicePtr(PtrBuilder, OldPtr->getType());
|
Value *NewPtr = getNewAllocaSlicePtr(PtrBuilder, OldPtr->getType());
|
||||||
|
@@ -566,3 +566,37 @@ merge:
|
|||||||
%4 = load float* %3, align 4
|
%4 = load float* %3, align 4
|
||||||
ret float %4
|
ret float %4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%struct.S = type { i32 }
|
||||||
|
|
||||||
|
; Verifies we fixed PR20822. We have a foldable PHI feeding a speculatable PHI
|
||||||
|
; which requires the rewriting of the speculated PHI to handle insertion
|
||||||
|
; when the incoming pointer is itself from a PHI node. We would previously
|
||||||
|
; insert a bitcast instruction *before* a PHI, producing an invalid module;
|
||||||
|
; make sure we insert *after* the first non-PHI instruction.
|
||||||
|
define void @PR20822() {
|
||||||
|
; CHECK-LABEL: @PR20822(
|
||||||
|
entry:
|
||||||
|
%f = alloca %struct.S, align 4
|
||||||
|
; CHECK: %[[alloca:.*]] = alloca
|
||||||
|
br i1 undef, label %if.end, label %for.cond
|
||||||
|
|
||||||
|
for.cond: ; preds = %for.cond, %entry
|
||||||
|
br label %if.end
|
||||||
|
|
||||||
|
if.end: ; preds = %for.cond, %entry
|
||||||
|
%f2 = phi %struct.S* [ %f, %entry ], [ %f, %for.cond ]
|
||||||
|
; CHECK: phi i32
|
||||||
|
; CHECK: %[[cast:.*]] = bitcast i32* %[[alloca]] to %struct.S*
|
||||||
|
phi i32 [ undef, %entry ], [ undef, %for.cond ]
|
||||||
|
br i1 undef, label %if.then5, label %if.then2
|
||||||
|
|
||||||
|
if.then2: ; preds = %if.end
|
||||||
|
br label %if.then5
|
||||||
|
|
||||||
|
if.then5: ; preds = %if.then2, %if.end
|
||||||
|
%f1 = phi %struct.S* [ undef, %if.then2 ], [ %f2, %if.end ]
|
||||||
|
; CHECK: phi {{.*}} %[[cast]]
|
||||||
|
store %struct.S undef, %struct.S* %f1, align 4
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user