[GVN] Don't use the eliminated load as an available value in phi construction
In ConstructSSAForLoadSet if an available value is actually the load that we're
doing SSA construction to eliminate, then we can omit it as SSAUpdate will add
in the value for the phi that will be replacing it anyway. This can result in
simpler IR which can allow further optimisation.
Differential Revision: https://reviews.llvm.org/D44160
llvm-svn: 337686
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index a8f52f0..1e0a22c 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -766,6 +766,15 @@
if (SSAUpdate.HasValueForBlock(BB))
continue;
+ // If the value is the load that we will be eliminating, and the block it's
+ // available in is the block that the load is in, then don't add it as
+ // SSAUpdater will resolve the value to the relevant phi which may let it
+ // avoid phi construction entirely if there's actually only one value.
+ if (BB == LI->getParent() &&
+ ((AV.AV.isSimpleValue() && AV.AV.getSimpleValue() == LI) ||
+ (AV.AV.isCoercedLoadValue() && AV.AV.getCoercedLoadValue() == LI)))
+ continue;
+
SSAUpdate.AddAvailableValue(BB, AV.MaterializeAdjustedValue(LI, gvn));
}