Index: lib/Transforms/Scalar/GVN.cpp =================================================================== --- lib/Transforms/Scalar/GVN.cpp +++ lib/Transforms/Scalar/GVN.cpp @@ -1328,12 +1328,14 @@ } // If this load follows a GEP, see if we can PRE the indices before analyzing. - if (GetElementPtrInst *GEP = dyn_cast(LI->getOperand(0))) { - for (GetElementPtrInst::op_iterator OI = GEP->idx_begin(), - OE = GEP->idx_end(); - OI != OE; ++OI) - if (Instruction *I = dyn_cast(OI->get())) - performScalarPRE(I); + if (EnablePRE) { + if (auto GEP = dyn_cast(LI->getOperand(0))) { + for (GetElementPtrInst::op_iterator OI = GEP->idx_begin(), + OE = GEP->idx_end(); + OI != OE; ++OI) + if (Instruction *I = dyn_cast(OI->get())) + performScalarPRE(I); + } } // Step 2: Analyze the availability of the load @@ -2143,6 +2145,7 @@ } bool GVN::performScalarPRE(Instruction *CurInst) { + assert(EnablePRE && "GVN: Calling performScalarPRE with -enable-pre=false."); if (isa(CurInst) || CurInst->isTerminator() || isa(CurInst) || CurInst->getType()->isVoidTy() || CurInst->mayReadFromMemory() || CurInst->mayHaveSideEffects() || Index: test/Transforms/GVN/nonescaping-malloc.ll =================================================================== --- test/Transforms/GVN/nonescaping-malloc.ll +++ test/Transforms/GVN/nonescaping-malloc.ll @@ -2,6 +2,10 @@ ; RUN: opt < %s -basicaa -gvn -stats -disable-output 2>&1 | FileCheck %s ; rdar://7363102 +; Sanity check that GVN::performScalarPRE is not called with +; enable-pre=false (asserts) +; RUN: opt < %s -basicaa -gvn -enable-pre=false -disable-output 2>&1 + ; CHECK: Number of loads deleted ; GVN should be able to eliminate load %tmp22.i, because it is redundant with