Index: lib/Analysis/InstructionSimplify.cpp =================================================================== --- lib/Analysis/InstructionSimplify.cpp +++ lib/Analysis/InstructionSimplify.cpp @@ -4542,7 +4542,7 @@ Value *llvm::SimplifyInstruction(Instruction *I, const SimplifyQuery &SQ, OptimizationRemarkEmitter *ORE) { const SimplifyQuery Q = SQ.CxtI ? SQ : SQ.getWithInstruction(I); - Value *Result; + Value *Result = nullptr; switch (I->getOpcode()) { default: @@ -4673,9 +4673,15 @@ Result = SimplifyCastInst(I->getOpcode(), I->getOperand(0), I->getType(), Q); break; + case Instruction::Load: { + auto *LI = cast(I); + if (!LI->isVolatile()) + if (auto *C = dyn_cast(LI->getOperand(0))) + Result = ConstantFoldLoadFromConstPtr(C, LI->getType(), Q.DL); + break; + } case Instruction::Alloca: // No simplifications for Alloca and it can't be constant folded. - Result = nullptr; break; }