Index: lib/Analysis/InstructionSimplify.cpp =================================================================== --- lib/Analysis/InstructionSimplify.cpp +++ lib/Analysis/InstructionSimplify.cpp @@ -4574,12 +4574,9 @@ 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: - Result = ConstantFoldInstruction(I, Q.DL, Q.TLI); - break; case Instruction::FAdd: Result = SimplifyFAddInst(I->getOperand(0), I->getOperand(1), I->getFastMathFlags(), Q); @@ -4712,6 +4709,10 @@ break; } + // Try to do constant folding if above simplifications had failed + if (!Result) + Result = ConstantFoldInstruction(I, Q.DL, Q.TLI); + // In general, it is possible for computeKnownBits to determine all bits in a // value even when the operands are not all constants. if (!Result && I->getType()->isIntOrIntVectorTy()) {