Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -13212,7 +13212,8 @@ SelectionDAG::FlagInserter FlagsInserter(DAG, N); // FMA nodes have flags that propagate to the created nodes. - bool UnsafeFPMath = Options.UnsafeFPMath || isContractable(N); + bool UnsafeFPMath = + Options.UnsafeFPMath || N->getFlags().hasAllowReassociation(); // Constant fold FMA. if (isa(N0) && Index: llvm/test/CodeGen/PowerPC/fma-combine.ll =================================================================== --- llvm/test/CodeGen/PowerPC/fma-combine.ll +++ llvm/test/CodeGen/PowerPC/fma-combine.ll @@ -333,8 +333,11 @@ ; CHECK: # %bb.0: # %entry ; CHECK-NEXT: addis 3, 2, .LCPI9_0@toc@ha ; CHECK-NEXT: lfd 0, .LCPI9_0@toc@l(3) -; CHECK-NEXT: xsmaddadp 2, 1, 0 +; CHECK-NEXT: addis 3, 2, .LCPI9_1@toc@ha +; CHECK-NEXT: lfd 3, .LCPI9_1@toc@l(3) +; CHECK-NEXT: xsmuldp 0, 1, 0 ; CHECK-NEXT: fmr 1, 2 +; CHECK-NEXT: xsmaddadp 1, 0, 3 ; CHECK-NEXT: blr entry: %0 = fmul double %a, 1.1