[PATCH] D22269: [SCCP] Replace structs with constants if all the lattice values are constant

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 1 09:21:44 PDT 2016

davide added inline comments.

Comment at: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp:1572
@@ +1571,3 @@
+                                  ? V.getConstant()
+                                  : UndefValue::get(ST->getElementType(i)));
+        }
reames wrote:
> Why must it be that any non-constant must be undef?  I suspect this is either a well known invariant in the code (with which I'm unfamiliar), or a possibly missing assert.
I have the algorithm out-of-cache but IIRC once the lattice solver runs there can't be values with an "undefined" lattice value, so, yes, this is an invariant maintained by the algorithm.

Comment at: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp:1580
@@ -1555,3 +1579,3 @@
-      Constant *Const = IV.isConstant()
-        ? IV.getConstant() : UndefValue::get(Inst->getType());
+        Const = IV.isConstant() ? IV.getConstant()
+                                : UndefValue::get(Inst->getType());
reames wrote:
> Is there a helper function which could common out this shared code?
I tried to factor out in a later commit (a while ago).

 `static bool tryToReplaceWithConstant(SCCPSolver &Solver, Value *V)` 

Does that make sense to you?



More information about the llvm-commits mailing list