[llvm] 3fedaf2 - [GVN] Don't explicitly materialize undefs from dead blocks

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 6 14:47:12 PST 2021


Author: Nikita Popov
Date: 2021-03-06T23:46:24+01:00
New Revision: 3fedaf2a522b5ca8db209a3864bf55978c407b29

URL: https://github.com/llvm/llvm-project/commit/3fedaf2a522b5ca8db209a3864bf55978c407b29
DIFF: https://github.com/llvm/llvm-project/commit/3fedaf2a522b5ca8db209a3864bf55978c407b29.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/GVN.cpp
    llvm/test/Transforms/GVN/load-dead-block.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index e8b8d477098e..b9171889005a 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -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;
 
@@ -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;

diff  --git a/llvm/test/Transforms/GVN/load-dead-block.ll b/llvm/test/Transforms/GVN/load-dead-block.ll
index f797973287a8..91a35d52021e 100644
--- a/llvm/test/Transforms/GVN/load-dead-block.ll
+++ b/llvm/test/Transforms/GVN/load-dead-block.ll
@@ -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


        


More information about the llvm-commits mailing list