Skip to content

Commit

Permalink
[GVN] Don't explicitly materialize undefs from dead blocks
Browse files Browse the repository at this point in the history
When materializing an available load value, do not explicitly
materialize the undef values from dead blocks. Doing so will
will force creation of a phi with an undef operand, even if there
is a dominating definition. The phi will be folded away on
subsequent GVN iterations, but by then we may have already
poisoned MDA cache slots.

Simply don't register these values in the first place, and let
SSAUpdater do its thing.
  • Loading branch information
nikic committed Mar 6, 2021
1 parent 5f319fc commit 3fedaf2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
7 changes: 4 additions & 3 deletions llvm/lib/Transforms/Scalar/GVN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,9 @@ static Value *ConstructSSAForLoadSet(LoadInst *LI,
for (const AvailableValueInBlock &AV : ValuesPerBlock) {
BasicBlock *BB = AV.BB;

if (AV.AV.isUndefValue())
continue;

if (SSAUpdate.HasValueForBlock(BB))
continue;

Expand Down Expand Up @@ -915,9 +918,7 @@ Value *AvailableValue::MaterializeAdjustedValue(LoadInst *LI,
<< *Res << '\n'
<< "\n\n\n");
} else {
assert(isUndefValue() && "Should be UndefVal");
LLVM_DEBUG(dbgs() << "GVN COERCED NONLOCAL Undef:\n";);
return UndefValue::get(LoadTy);
llvm_unreachable("Should not materialize value from dead block");
}
assert(Res && "failed to materialize?");
return Res;
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/Transforms/GVN/load-dead-block.ll
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ define i64 @test(i64** noalias %p, i64* noalias %q) {
; CHECK-NEXT: store i64 1, i64* [[Q]], align 4
; CHECK-NEXT: [[Q3:%.*]] = getelementptr i64, i64* [[Q]], i64 1
; CHECK-NEXT: store i64 2, i64* [[Q3]], align 4
; CHECK-NEXT: [[V2:%.*]] = load i64, i64* [[Q]], align 4
; CHECK-NEXT: ret i64 [[V2]]
; CHECK-NEXT: ret i64 1
;
entry:
store i64* %q, i64** %p
Expand Down

0 comments on commit 3fedaf2

Please sign in to comment.