mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
NewGVN: Fix PHI evaluation bug exposed by new verifier. We were checking whether the incoming block was reachable instead of whether the specific edge was reachable
llvm-svn: 298187
This commit is contained in:
parent
a267a93237
commit
54d98b54f5
@ -444,7 +444,7 @@ PHIExpression *NewGVN::createPHIExpression(Instruction *I) {
|
||||
|
||||
// Filter out unreachable phi operands.
|
||||
auto Filtered = make_filter_range(PN->operands(), [&](const Use &U) {
|
||||
return ReachableBlocks.count(PN->getIncomingBlock(U));
|
||||
return ReachableEdges.count({PN->getIncomingBlock(U), PHIBlock});
|
||||
});
|
||||
|
||||
std::transform(Filtered.begin(), Filtered.end(), op_inserter(E),
|
||||
@ -1740,10 +1740,11 @@ void NewGVN::valueNumberMemoryPhi(MemoryPhi *MP) {
|
||||
// If all the arguments are the same, the MemoryPhi has the same value as the
|
||||
// argument.
|
||||
// Filter out unreachable blocks and self phis from our operands.
|
||||
const BasicBlock *PHIBlock = MP->getBlock();
|
||||
auto Filtered = make_filter_range(MP->operands(), [&](const Use &U) {
|
||||
return lookupMemoryAccessEquiv(cast<MemoryAccess>(U)) != MP &&
|
||||
!isMemoryAccessTop(cast<MemoryAccess>(U)) &&
|
||||
ReachableBlocks.count(MP->getIncomingBlock(U));
|
||||
ReachableEdges.count({MP->getIncomingBlock(U), PHIBlock});
|
||||
});
|
||||
// If all that is left is nothing, our memoryphi is undef. We keep it as
|
||||
// InitialClass. Note: The only case this should happen is if we have at
|
||||
@ -1822,7 +1823,7 @@ bool NewGVN::singleReachablePHIPath(const MemoryAccess *First,
|
||||
} else {
|
||||
auto *MP = cast<MemoryPhi>(First);
|
||||
auto ReachableOperandPred = [&](const Use &U) {
|
||||
return ReachableBlocks.count(MP->getIncomingBlock(U));
|
||||
return ReachableEdges.count({MP->getIncomingBlock(U), MP->getBlock()});
|
||||
};
|
||||
auto FilteredPhiArgs =
|
||||
make_filter_range(MP->operands(), ReachableOperandPred);
|
||||
@ -1879,7 +1880,8 @@ void NewGVN::verifyMemoryCongruency() const {
|
||||
// We can only sanely verify that MemoryDefs in the operand list all have
|
||||
// the same class.
|
||||
auto ReachableOperandPred = [&](const Use &U) {
|
||||
return ReachableBlocks.count(FirstMP->getIncomingBlock(U)) &&
|
||||
return ReachableEdges.count(
|
||||
{FirstMP->getIncomingBlock(U), FirstMP->getBlock()}) &&
|
||||
isa<MemoryDef>(U);
|
||||
|
||||
};
|
||||
|
60
test/Transforms/NewGVN/phi-edge-handling.ll
Normal file
60
test/Transforms/NewGVN/phi-edge-handling.ll
Normal file
@ -0,0 +1,60 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt < %s -newgvn -S | FileCheck %s
|
||||
|
||||
|
||||
;; Block 6 is reachable, but edge 6->4 is not
|
||||
;; This means the phi value is undef, not 0
|
||||
; Function Attrs: ssp uwtable
|
||||
define i16 @hoge() local_unnamed_addr #0 align 2 {
|
||||
; CHECK-LABEL: @hoge(
|
||||
; CHECK-NEXT: bb:
|
||||
; CHECK-NEXT: switch i8 undef, label [[BB7:%.*]] [
|
||||
; CHECK-NEXT: i8 0, label [[BB1:%.*]]
|
||||
; CHECK-NEXT: i8 12, label [[BB2:%.*]]
|
||||
; CHECK-NEXT: ]
|
||||
; CHECK: bb1:
|
||||
; CHECK-NEXT: br label [[BB6:%.*]]
|
||||
; CHECK: bb2:
|
||||
; CHECK-NEXT: br label [[BB4:%.*]]
|
||||
; CHECK: bb3:
|
||||
; CHECK-NEXT: unreachable
|
||||
; CHECK: bb4:
|
||||
; CHECK-NEXT: ret i16 undef
|
||||
; CHECK: bb6:
|
||||
; CHECK-NEXT: br i1 true, label [[BB3:%.*]], label [[BB4]], !llvm.loop !1
|
||||
; CHECK: bb7:
|
||||
; CHECK-NEXT: unreachable
|
||||
;
|
||||
bb:
|
||||
switch i8 undef, label %bb7 [
|
||||
i8 0, label %bb1
|
||||
i8 12, label %bb2
|
||||
]
|
||||
|
||||
bb1: ; preds = %bb
|
||||
br label %bb6
|
||||
|
||||
bb2: ; preds = %bb
|
||||
br label %bb4
|
||||
|
||||
bb3: ; preds = %bb6
|
||||
unreachable
|
||||
|
||||
bb4: ; preds = %bb6, %bb2
|
||||
%tmp = phi i16 [ 0, %bb6 ], [ undef, %bb2 ]
|
||||
ret i16 %tmp
|
||||
|
||||
bb6: ; preds = %bb4
|
||||
br i1 true, label %bb3, label %bb4, !llvm.loop !1
|
||||
|
||||
bb7: ; preds = %bb
|
||||
unreachable
|
||||
}
|
||||
|
||||
attributes #0 = { ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
|
||||
!llvm.ident = !{!0}
|
||||
|
||||
!0 = !{!"clang version 5.0.0 (http://llvm.org/git/clang.git a8b933d4d1d133594fdaed35ee5814514b738f6d) (/Users/dannyb/sources/llvm-clean fc630a9b5613f544c07a8f16abcc173793df62cf)"}
|
||||
!1 = distinct !{!1, !2}
|
||||
!2 = !{!"llvm.loop.unroll.disable"}
|
Loading…
Reference in New Issue
Block a user