[llvm] [InstSimplify] Check call for FMF instead of CtxI (PR #71585)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 7 12:38:49 PST 2023


https://github.com/annamthomas created https://github.com/llvm/llvm-project/pull/71585

This code was incorrectly checking that the CtxI has required FMF, but
the context instruction need not always be the instrinsic call.

Check that the intrinsic call has the required FMF.

Fixes PR71548.


>From cfb504fe717483bc441aa2f4bf3426728021b2bd Mon Sep 17 00:00:00 2001
From: Anna Thomas <anna at azul.com>
Date: Tue, 7 Nov 2023 15:32:12 -0500
Subject: [PATCH] [InstSimplify] Check call for FMF instead of CtxI

This code was incorrectly checking that the CtxI has required FMF, but
the context instruction need not always be the instrinsic call.

Check that the intrinsic call has the required FMF.

Fixes PR71548.
---
 llvm/lib/Analysis/InstructionSimplify.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index ad51e163062012e..bec20d75f004422 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -6346,7 +6346,8 @@ static Value *foldMinimumMaximumSharedOp(Intrinsic::ID IID, Value *Op0,
 }
 
 static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
-                                      const SimplifyQuery &Q) {
+                                      const SimplifyQuery &Q,
+                                      const CallBase *Call) {
   Intrinsic::ID IID = F->getIntrinsicID();
   Type *ReturnType = F->getReturnType();
   unsigned BitWidth = ReturnType->getScalarSizeInBits();
@@ -6606,20 +6607,19 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
     // float, if the ninf flag is set.
     const APFloat *C;
     if (match(Op1, m_APFloat(C)) &&
-        (C->isInfinity() || (isa<FPMathOperator>(Q.CxtI) &&
-                             Q.CxtI->hasNoInfs() && C->isLargest()))) {
+        (C->isInfinity() || (Call->hasNoInfs() && C->isLargest()))) {
       // minnum(X, -inf) -> -inf
       // maxnum(X, +inf) -> +inf
       // minimum(X, -inf) -> -inf if nnan
       // maximum(X, +inf) -> +inf if nnan
-      if (C->isNegative() == IsMin && (!PropagateNaN || Q.CxtI->hasNoNaNs()))
+      if (C->isNegative() == IsMin && (!PropagateNaN || Call->hasNoNaNs()))
         return ConstantFP::get(ReturnType, *C);
 
       // minnum(X, +inf) -> X if nnan
       // maxnum(X, -inf) -> X if nnan
       // minimum(X, +inf) -> X
       // maximum(X, -inf) -> X
-      if (C->isNegative() != IsMin && (PropagateNaN || Q.CxtI->hasNoNaNs()))
+      if (C->isNegative() != IsMin && (PropagateNaN || Call->hasNoNaNs()))
         return Op0;
     }
 
@@ -6681,7 +6681,7 @@ static Value *simplifyIntrinsic(CallBase *Call, Value *Callee,
     return simplifyUnaryIntrinsic(F, Args[0], Q);
 
   if (NumOperands == 2)
-    return simplifyBinaryIntrinsic(F, Args[0], Args[1], Q);
+    return simplifyBinaryIntrinsic(F, Args[0], Args[1], Q, Call);
 
   // Handle intrinsics with 3 or more arguments.
   switch (IID) {



More information about the llvm-commits mailing list