Fix the inline cost calculation to take into account instructions
authorEli Friedman <eli.friedman@gmail.com>
Sat, 18 Jul 2009 05:26:06 +0000 (05:26 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 18 Jul 2009 05:26:06 +0000 (05:26 +0000)
which cannot be folded even if they have constant operands. Significantly
helps if_spppsubr.c attached to PR4573.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76285 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/InlineCost.cpp

index 87aff01a58576804615c0f4f7faa0c3083934bf7..5fe85e6ef29e29bfec9714bfffbf5de921e09eec 100644 (file)
@@ -42,6 +42,13 @@ unsigned InlineCostAnalyzer::FunctionInfo::
       // Figure out if this instruction will be removed due to simple constant
       // propagation.
       Instruction &Inst = cast<Instruction>(**UI);
+      
+      // We can't constant propagate instructions which have effects or
+      // read memory.
+      if (Inst.mayReadFromMemory() || Inst.mayHaveSideEffects() ||
+          isa<AllocationInst>(Inst))
+        continue;
+
       bool AllOperandsConstant = true;
       for (unsigned i = 0, e = Inst.getNumOperands(); i != e; ++i)
         if (!isa<Constant>(Inst.getOperand(i)) && Inst.getOperand(i) != V) {