The fma libcalls are defined in Builtins.def using the 'e' attribute that says that its only const if -fno-math-errno. It was apparently marked this way because that's what the posix spec says. This determines whether the call gets marked as const or not in SemaDecl.cpp. But in CGBuiltins.cpp we are blindly emitting an intrinsic no matter whether the call is const or not.
This patch changes Builtins.def to match the current CGBuiltins behavior and updates CGBuiltins to check if the function is const. So if anyone ever changes Builtins.def in the future it will do the right thing.