[llvm] [InstSimplify] Optimize maximumnum and minimumnum (PR #139581)

Lewis Crawford via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 3 07:49:42 PDT 2025


================
@@ -6741,15 +6741,14 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType,
 
     // minnum(x, qnan) -> x
     // maxnum(x, qnan) -> x
-    // minnum(x, snan) -> qnan
-    // maxnum(x, snan) -> qnan
+    // minnum(x, snan) -> qnan (or x for vectors mixing snans and qnans)
+    // maxnum(x, snan) -> qnan (or x for vectors mixing snans and qnans)
----------------
LewisCrawford wrote:

We cannot handle maxnum(<x, y>, <sNaN, qNaN>) elementwise here if we want to propagate the sNaN, because we would need to return <qNaN, y>, which would require a vector-shuffle instruction, and InstructionSimplify is not allowed to insert new instruction. It can only return either the full vector <x, y> or a new constant vector. In the new elementwise version I've just written, I've kept this behaviour of just disabling the optimization in this case, as we'd need 1 element from the LHS, and 1 from the RHS.

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


More information about the llvm-commits mailing list