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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 23 18:07:23 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(
+              NewInst, BB->getModule()->getDataLayout())) {
+        if (wouldInstructionBeTriviallyDead(NewInst)) {
----------------
nikic wrote:

I'd personally use isInstructionTriviallyDead here just to be more obvious (even though we know that there are no uses at this point.)

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


More information about the llvm-commits mailing list