[llvm] [ConstantRange] Add binaryOp supporting 'or disjoint'. (PR #222573)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 03:06:57 PDT 2026


================
@@ -1044,6 +1044,23 @@ ConstantRange ConstantRange::overflowingBinaryOp(Instruction::BinaryOps BinOp,
   }
 }
 
+ConstantRange ConstantRange::binaryOp(const BinaryOperator &BO,
+                                      const ConstantRange &Other) const {
+  if (const auto *OBO = dyn_cast<OverflowingBinaryOperator>(&BO))
+    return overflowingBinaryOp(BO.getOpcode(), Other, OBO->getNoWrapKind());
+
+  // Treat 'or disjoint' as both 'add nuw nsw' and binary or, picking the best
+  // from both.
+  const auto *PDI = dyn_cast<PossiblyDisjointInst>(&BO);
+  if (PDI && PDI->isDisjoint()) {
+    using OBO = OverflowingBinaryOperator;
+    return addWithNoWrap(Other, OBO::NoUnsignedWrap | OBO::NoSignedWrap)
+        .intersectWith(binaryOr(Other));
----------------
nikic wrote:

Can you please add a separate method for this (or a parameter to binaryOr if convenient)? This should be available without having to construct a BinaryOperator, e.g. for the unit test.

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


More information about the llvm-commits mailing list