Index: lib/Analysis/InstructionSimplify.cpp =================================================================== --- lib/Analysis/InstructionSimplify.cpp +++ lib/Analysis/InstructionSimplify.cpp @@ -791,7 +791,7 @@ if (Constant *CRHS = dyn_cast(Op1)) { Constant *Ops[] = { CLHS, CRHS }; return ConstantFoldInstOperands(Instruction::FAdd, CLHS->getType(), - Ops, Q.DL, Q.TLI); + Ops, Q.DL, Q.TLI, FMF); } // Canonicalize the constant to the RHS. @@ -833,7 +833,7 @@ if (Constant *CRHS = dyn_cast(Op1)) { Constant *Ops[] = { CLHS, CRHS }; return ConstantFoldInstOperands(Instruction::FSub, CLHS->getType(), - Ops, Q.DL, Q.TLI); + Ops, Q.DL, Q.TLI, FMF); } } @@ -871,7 +871,7 @@ if (Constant *CRHS = dyn_cast(Op1)) { Constant *Ops[] = { CLHS, CRHS }; return ConstantFoldInstOperands(Instruction::FMul, CLHS->getType(), - Ops, Q.DL, Q.TLI); + Ops, Q.DL, Q.TLI, FMF); } // Canonicalize the constant to the RHS. Index: test/Transforms/InstSimplify/fast-math.ll =================================================================== --- test/Transforms/InstSimplify/fast-math.ll +++ test/Transforms/InstSimplify/fast-math.ll @@ -171,3 +171,51 @@ ; CHECK-LABEL: fdiv_neg_swapped2 ; CHECK: ret float -1.000000e+00 } + +; CHECK-LABEL: @nofold_fadd_nexc( +define double @nofold_fadd_nexc() { +; CHECK: fadd +entry: + %val = fadd nrnd double 1.000000e+308, 1.000000e+308 + ret double %val +} + +; CHECK-LABEL: @nofold_fsub_nexc( +define double @nofold_fsub_nexc() { +; CHECK: fsub +entry: + %val = fsub nrnd double 1.000000e-308, 1.000000e+308 + ret double %val +} + +; CHECK-LABEL: @nofold_fmul_nexc( +define double @nofold_fmul_nexc() { +; CHECK: fmul +entry: + %val = fmul nrnd double 1.000000e+300, 1.000000e+300 + ret double %val +} + +; CHECK-LABEL: @nofold_fadd_nrnd( +define double @nofold_fadd_nrnd() { +; CHECK: fadd +entry: + %val = fadd nexc double 1.000000e+308, 1.000000e+308 + ret double %val +} + +; CHECK-LABEL: @nofold_fsub_nrnd( +define double @nofold_fsub_nrnd() { +; CHECK: fsub +entry: + %val = fsub nexc double 1.000000e-308, 1.000000e+308 + ret double %val +} + +; CHECK-LABEL: @nofold_fmul_nrnd( +define double @nofold_fmul_nrnd() { +; CHECK: fmul +entry: + %val = fmul nexc double 1.000000e+300, 1.000000e+300 + ret double %val +}