[llvm] [InstSimplify] Simplify the select with integer comparison relationship (PR #66668)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 09:45:41 PDT 2023


================
@@ -4547,6 +4547,20 @@ static Value *simplifySelectWithICmpEq(Value *CmpLHS, Value *CmpRHS,
   return nullptr;
 }
 
+/// Return nullptr if the comparison relationship of X and Y can't be inferred.
+static Value *simplifySelectWithICmpKnownRelation(ICmpInst::Predicate Pred,
+                                                  Value *CmpLHS, Value *CmpRHS,
+                                                  Value *TrueVal,
+                                                  Value *FalseVal,
+                                                  const SimplifyQuery &Q) {
+  if (std::optional<bool> Flag =
+          isImpliedByDomCondition(Pred, CmpLHS, CmpRHS, Q.CxtI, Q.DL)) {
+    if (Flag)
+      return *Flag ? TrueVal : FalseVal;
+  }
+  return nullptr;
----------------
goldsteinn wrote:

You can fallback on knownbits. See `InstCombeCalls::getKnownSign`.
In fact, I'd say a better approach would be to port `getKnownSign` to a mutually accessible location (maybe `ValueTracking` then just that here.

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


More information about the llvm-commits mailing list