[llvm-branch-commits] [llvm-branch] r223639 - Merging r216891:
David Majnemer
david.majnemer at gmail.com
Mon Dec 8 00:53:47 PST 2014
Author: majnemer
Date: Mon Dec 8 02:53:47 2014
New Revision: 223639
URL: http://llvm.org/viewvc/llvm-project?rev=223639&view=rev
Log:
Merging r216891:
------------------------------------------------------------------------
r216891 | majnemer | 2014-09-01 14:20:14 -0700 (Mon, 01 Sep 2014) | 12 lines
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
------------------------------------------------------------------------
Modified:
llvm/branches/release_35/ (props changed)
llvm/branches/release_35/lib/Transforms/Scalar/SROA.cpp
llvm/branches/release_35/test/Transforms/SROA/phi-and-select.ll
Propchange: llvm/branches/release_35/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Dec 8 02:53:47 2014
@@ -1,3 +1,3 @@
/llvm/branches/Apple/Pertwee:110850,110961
/llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,213653,213665,213726,213749,213773,213793,213798-213799,213815,213847,213880,213883-213884,213894-213896,213899,213915,213966,213999,214060,214129,214180,214287,214331,214423,214429,214519,214670,214674,214679,215685,215711,215806,216064,216262,216531,216920,217102,217115,217257,218745,221009,221408,221453,221501,222338,222376,223163,223170-223171
+/llvm/trunk:155241,213653,213665,213726,213749,213773,213793,213798-213799,213815,213847,213880,213883-213884,213894-213896,213899,213915,213966,213999,214060,214129,214180,214287,214331,214423,214429,214519,214670,214674,214679,215685,215711,215806,216064,216262,216531,216891,216920,217102,217115,217257,218745,221009,221408,221453,221501,222338,222376,223163,223170-223171
Modified: llvm/branches/release_35/lib/Transforms/Scalar/SROA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_35/lib/Transforms/Scalar/SROA.cpp?rev=223639&r1=223638&r2=223639&view=diff
==============================================================================
--- llvm/branches/release_35/lib/Transforms/Scalar/SROA.cpp (original)
+++ llvm/branches/release_35/lib/Transforms/Scalar/SROA.cpp Mon Dec 8 02:53:47 2014
@@ -2697,7 +2697,10 @@ private:
// the old pointer, which necessarily must be in the right position to
// dominate the PHI.
IRBuilderTy PtrBuilder(IRB);
- PtrBuilder.SetInsertPoint(OldPtr);
+ if (isa<PHINode>(OldPtr))
+ PtrBuilder.SetInsertPoint(OldPtr->getParent()->getFirstInsertionPt());
+ else
+ PtrBuilder.SetInsertPoint(OldPtr);
PtrBuilder.SetCurrentDebugLocation(OldPtr->getDebugLoc());
Value *NewPtr = getNewAllocaSlicePtr(PtrBuilder, OldPtr->getType());
Modified: llvm/branches/release_35/test/Transforms/SROA/phi-and-select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_35/test/Transforms/SROA/phi-and-select.ll?rev=223639&r1=223638&r2=223639&view=diff
==============================================================================
--- llvm/branches/release_35/test/Transforms/SROA/phi-and-select.ll (original)
+++ llvm/branches/release_35/test/Transforms/SROA/phi-and-select.ll Mon Dec 8 02:53:47 2014
@@ -501,3 +501,102 @@ end:
; CHECK-NOT: load
; CHECK: ret float %[[phi]]
}
+
+; Verifies we fixed PR20425. We should be able to promote all alloca's to
+; registers in this test.
+;
+; %0 = slice
+; %1 = slice
+; %2 = phi(%0, %1) // == slice
+define float @simplify_phi_nodes_that_equal_slice(i1 %cond, float* %temp) {
+; CHECK-LABEL: @simplify_phi_nodes_that_equal_slice(
+entry:
+ %arr = alloca [4 x float], align 4
+; CHECK-NOT: alloca
+ br i1 %cond, label %then, label %else
+
+then:
+ %0 = getelementptr inbounds [4 x float]* %arr, i64 0, i64 3
+ store float 1.000000e+00, float* %0, align 4
+ br label %merge
+
+else:
+ %1 = getelementptr inbounds [4 x float]* %arr, i64 0, i64 3
+ store float 2.000000e+00, float* %1, align 4
+ br label %merge
+
+merge:
+ %2 = phi float* [ %0, %then ], [ %1, %else ]
+ store float 0.000000e+00, float* %temp, align 4
+ %3 = load float* %2, align 4
+ ret float %3
+}
+
+; A slightly complicated example for PR20425.
+;
+; %0 = slice
+; %1 = phi(%0) // == slice
+; %2 = slice
+; %3 = phi(%1, %2) // == slice
+define float @simplify_phi_nodes_that_equal_slice_2(i1 %cond, float* %temp) {
+; CHECK-LABEL: @simplify_phi_nodes_that_equal_slice_2(
+entry:
+ %arr = alloca [4 x float], align 4
+; CHECK-NOT: alloca
+ br i1 %cond, label %then, label %else
+
+then:
+ %0 = getelementptr inbounds [4 x float]* %arr, i64 0, i64 3
+ store float 1.000000e+00, float* %0, align 4
+ br label %then2
+
+then2:
+ %1 = phi float* [ %0, %then ]
+ store float 2.000000e+00, float* %1, align 4
+ br label %merge
+
+else:
+ %2 = getelementptr inbounds [4 x float]* %arr, i64 0, i64 3
+ store float 3.000000e+00, float* %2, align 4
+ br label %merge
+
+merge:
+ %3 = phi float* [ %1, %then2 ], [ %2, %else ]
+ store float 0.000000e+00, float* %temp, align 4
+ %4 = load float* %3, align 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
+}
More information about the llvm-branch-commits
mailing list