[llvm] [Inline][Cloning] Defer constant propagation after phi-nodes resolution (PR #87963)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 23 13:50:08 PDT 2024


================
@@ -540,18 +541,11 @@ void PruningFunctionCloner::CloneBlock(
       RemapInstruction(NewInst, VMap,
                        ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges);
 
-      // If we can simplify this instruction to some other value, simply add
-      // a mapping to that value rather than inserting a new instruction into
-      // the basic block.
-      if (Value *V =
-              simplifyInstruction(NewInst, BB->getModule()->getDataLayout())) {
-        // On the off-chance that this simplifies to an instruction in the old
-        // function, map it back into the new function.
-        if (NewFunc != OldFunc)
-          if (Value *MappedV = VMap.lookup(V))
-            V = MappedV;
-
-        if (!NewInst->mayHaveSideEffects()) {
+      // Eagerly constant fold the newly cloned instruction. If successful, add
+      // a mapping to the new value.
+      if (Value *V = ConstantFoldInstruction(
----------------
efriedma-quic wrote:

Maybe worth explicitly noting that non-constant operands might not incomplete at this point, so we don't want to try to do simplifications based on them.

https://github.com/llvm/llvm-project/pull/87963


More information about the llvm-commits mailing list