Commit aaa653d4 authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r276389:

------------------------------------------------------------------------
r276389 | majnemer | 2016-07-21 21:54:44 -0700 (Thu, 21 Jul 2016) | 6 lines

Don't remove side effecting instructions due to ConstantFoldInstruction

Just because we can constant fold the result of an instruction does not
imply that we can delete the instruction.  It may have side effects.

This fixes PR28655.
------------------------------------------------------------------------

llvm-svn: 276660
parent 8e554281
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@
#include "llvm/Transforms/Utils/CtorUtils.h"
#include "llvm/Transforms/Utils/Evaluator.h"
#include "llvm/Transforms/Utils/GlobalStatus.h"
#include "llvm/Transforms/Utils/Local.h"
#include <algorithm>
using namespace llvm;

@@ -779,6 +780,7 @@ static void ConstantPropUsersOf(Value *V, const DataLayout &DL,
        // Instructions could multiply use V.
        while (UI != E && *UI == I)
          ++UI;
        if (isInstructionTriviallyDead(I, TLI))
          I->eraseFromParent();
      }
}
+6 −3
Original line number Diff line number Diff line
@@ -2830,6 +2830,7 @@ bool InstCombiner::run() {
        // Add operands to the worklist.
        replaceInstUsesWith(*I, C);
        ++NumConstProp;
        if (isInstructionTriviallyDead(I, TLI))
          eraseInstFromFunction(*I);
        MadeIRChange = true;
        continue;
@@ -2851,6 +2852,7 @@ bool InstCombiner::run() {
        // Add operands to the worklist.
        replaceInstUsesWith(*I, C);
        ++NumConstProp;
        if (isInstructionTriviallyDead(I, TLI))
          eraseInstFromFunction(*I);
        MadeIRChange = true;
        continue;
@@ -3007,6 +3009,7 @@ static bool AddReachableCodeToWorklist(BasicBlock *BB, const DataLayout &DL,
                       << *Inst << '\n');
          Inst->replaceAllUsesWith(C);
          ++NumConstProp;
          if (isInstructionTriviallyDead(Inst, TLI))
            Inst->eraseFromParent();
          continue;
        }
+5 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
//===----------------------------------------------------------------------===//

#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/IR/Constant.h"
@@ -90,11 +91,13 @@ bool ConstantPropagation::runOnFunction(Function &F) {

        // Remove the dead instruction.
        WorkList.erase(I);
        if (isInstructionTriviallyDead(I, TLI)) {
          I->eraseFromParent();
          ++NumInstKilled;
        }

        // We made a change to the function...
        Changed = true;
        ++NumInstKilled;
      }
  }
  return Changed;
+2 −1
Original line number Diff line number Diff line
@@ -758,6 +758,7 @@ bool JumpThreadingPass::ProcessBlock(BasicBlock *BB) {
        ConstantFoldInstruction(I, BB->getModule()->getDataLayout(), TLI);
    if (SimpleVal) {
      I->replaceAllUsesWith(SimpleVal);
      if (isInstructionTriviallyDead(I, TLI))
        I->eraseFromParent();
      Condition = SimpleVal;
    }
+4 −2
Original line number Diff line number Diff line
@@ -377,9 +377,11 @@ bool llvm::hoistRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
              &I, I.getModule()->getDataLayout(), TLI)) {
        DEBUG(dbgs() << "LICM folding inst: " << I << "  --> " << *C << '\n');
        CurAST->copyValue(&I, C);
        CurAST->deleteValue(&I);
        I.replaceAllUsesWith(C);
        if (isInstructionTriviallyDead(&I, TLI)) {
          CurAST->deleteValue(&I);
          I.eraseFromParent();
        }
        continue;
      }

Loading