Skip to content

Commit 3fedaf2

Browse files
committed
[GVN] Don't explicitly materialize undefs from dead blocks
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.
1 parent 5f319fc commit 3fedaf2

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,9 @@ static Value *ConstructSSAForLoadSet(LoadInst *LI,
855855
for (const AvailableValueInBlock &AV : ValuesPerBlock) {
856856
BasicBlock *BB = AV.BB;
857857

858+
if (AV.AV.isUndefValue())
859+
continue;
860+
858861
if (SSAUpdate.HasValueForBlock(BB))
859862
continue;
860863

@@ -915,9 +918,7 @@ Value *AvailableValue::MaterializeAdjustedValue(LoadInst *LI,
915918
<< *Res << '\n'
916919
<< "\n\n\n");
917920
} else {
918-
assert(isUndefValue() && "Should be UndefVal");
919-
LLVM_DEBUG(dbgs() << "GVN COERCED NONLOCAL Undef:\n";);
920-
return UndefValue::get(LoadTy);
921+
llvm_unreachable("Should not materialize value from dead block");
921922
}
922923
assert(Res && "failed to materialize?");
923924
return Res;

llvm/test/Transforms/GVN/load-dead-block.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ define i64 @test(i64** noalias %p, i64* noalias %q) {
1313
; CHECK-NEXT: store i64 1, i64* [[Q]], align 4
1414
; CHECK-NEXT: [[Q3:%.*]] = getelementptr i64, i64* [[Q]], i64 1
1515
; CHECK-NEXT: store i64 2, i64* [[Q3]], align 4
16-
; CHECK-NEXT: [[V2:%.*]] = load i64, i64* [[Q]], align 4
17-
; CHECK-NEXT: ret i64 [[V2]]
16+
; CHECK-NEXT: ret i64 1
1817
;
1918
entry:
2019
store i64* %q, i64** %p

0 commit comments

Comments
 (0)