[llvm] InstSimplify: support floating-point equivalences (PR #115152)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 8 06:14:07 PST 2024


================
@@ -4761,28 +4761,54 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal,
 /// Try to simplify a select instruction when its condition operand is a
 /// floating-point comparison.
 static Value *simplifySelectWithFCmp(Value *Cond, Value *T, Value *F,
-                                     const SimplifyQuery &Q) {
+                                     const SimplifyQuery &Q,
+                                     unsigned MaxRecurse) {
   FCmpInst::Predicate Pred;
-  if (!match(Cond, m_FCmp(Pred, m_Specific(T), m_Specific(F))) &&
-      !match(Cond, m_FCmp(Pred, m_Specific(F), m_Specific(T))))
+  Value *CmpLHS, *CmpRHS;
+  if (!match(Cond, m_FCmp(Pred, m_Value(CmpLHS), m_Value(CmpRHS))))
+    return nullptr;
+  FCmpInst *I = cast<FCmpInst>(Cond);
+
+  bool IsEquiv = I->isEquivalence(),
+       IsInverseEquiv = I->isEquivalence(/*Invert=*/true);
----------------
artagnon wrote:

I don't think there a way around this awkward API: if we return the predicate where it is equivalent, we still need to check three different predicates to tell whether or not to invert the TrueVal and FalseVal. I thought about returning an `std::optional<bool>` which would convey all the information with one call, but it's not much better than calling it twice and keeping two bools: we would be doing the same amount of work, and at least we wouldn't be uglifying isEquivalence.

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


More information about the llvm-commits mailing list