================
@@ -10237,39 +10269,25 @@ ConstantRange llvm::computeConstantRange(const Value 
*V, bool ForSigned,
   InstrInfoQuery IIQ(UseInstrInfo);
   ConstantRange CR = ConstantRange::getFull(BitWidth);
   if (auto *BO = dyn_cast<BinaryOperator>(V)) {
-    APInt Lower = APInt(BitWidth, 0);
-    APInt Upper = APInt(BitWidth, 0);
-    // TODO: Return ConstantRange.
-    setLimitsForBinOp(*BO, Lower, Upper, IIQ, ForSigned);
-    CR = ConstantRange::getNonEmpty(Lower, Upper);
-    if (BO->getOpcode() == Instruction::Add ||
-        BO->getOpcode() == Instruction::Sub) {
-      ConstantRange LHS = computeConstantRange(
-          BO->getOperand(0), ForSigned, UseInstrInfo, AC, CtxI, DT, Depth + 1);
-      ConstantRange RHS = computeConstantRange(
-          BO->getOperand(1), ForSigned, UseInstrInfo, AC, CtxI, DT, Depth + 1);
-      unsigned NoWrapKind = 0;
-      if (IIQ.hasNoUnsignedWrap(BO))
-        NoWrapKind |= OverflowingBinaryOperator::NoUnsignedWrap;
-      if (IIQ.hasNoSignedWrap(BO))
-        NoWrapKind |= OverflowingBinaryOperator::NoSignedWrap;
-      ConstantRange OpCR = BO->getOpcode() == Instruction::Add
-                               ? LHS.addWithNoWrap(RHS, NoWrapKind)
-                               : LHS.subWithNoWrap(RHS, NoWrapKind);
-      CR = CR.intersectWith(OpCR);
-    }
-  } else if (auto *SExt = dyn_cast<SExtInst>(V)) {
-    CR = computeConstantRange(SExt->getOperand(0), ForSigned, UseInstrInfo, AC,
-                              CtxI, DT, Depth + 1)
-             .signExtend(BitWidth);
-  } else if (auto *ZExt = dyn_cast<ZExtInst>(V)) {
-    CR = computeConstantRange(ZExt->getOperand(0), ForSigned, UseInstrInfo, AC,
-                              CtxI, DT, Depth + 1)
-             .zeroExtend(BitWidth);
-  } else if (auto *Trunc = dyn_cast<TruncInst>(V)) {
-    CR = computeConstantRange(Trunc->getOperand(0), ForSigned, UseInstrInfo, 
AC,
-                              CtxI, DT, Depth + 1)
-             .truncate(BitWidth);
+    CR = getRangeForBinOp(*BO, ForSigned, UseInstrInfo, AC, CtxI, DT, Depth);
+  } else if (isa<SExtInst>(V) || isa<ZExtInst>(V) || isa<TruncInst>(V)) {
+    auto *CastOp = cast<CastInst>(V);
+    ConstantRange OpCR =
+        computeConstantRange(CastOp->getOperand(0), ForSigned, UseInstrInfo, 
AC,
----------------
mgudim wrote:

why do yo need the `CastOp`? can you just use `V->getOperand(0)`?

https://github.com/llvm/llvm-project/pull/181110
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to