[llvm] [InstCombine] Fix FMF propagation in `copysign Mag, (copysign ?, X) -> copysign Mag, X` (PR #121574)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 4 06:13:04 PST 2025


================
@@ -2645,8 +2645,12 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
     // copysign Mag, (copysign ?, X) --> copysign Mag, X
     Value *X;
     if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X)))) {
-      II->andIRFlags(Sign);
-      return replaceOperand(*II, 1, X);
+      IRBuilder<>::FastMathFlagGuard FMFGuard(Builder);
+      Builder.setFastMathFlags(II->getFastMathFlags() &
+                               cast<Instruction>(Sign)->getFastMathFlags());
+      Value *CopySign =
+          Builder.CreateBinaryIntrinsic(Intrinsic::copysign, Mag, X);
----------------
dtcxzyw wrote:

I am working on a prototype.


https://github.com/llvm/llvm-project/pull/121574


More information about the llvm-commits mailing list