[llvm] [SCCP] Extend `visitBinaryOperator` to overflowing binary ops (PR #84470)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 8 04:38:27 PST 2024
================
@@ -1486,7 +1486,18 @@ void SCCPInstVisitor::visitBinaryOperator(Instruction &I) {
// Try to simplify to a constant range.
ConstantRange A = getConstantRange(V1State, I.getType());
ConstantRange B = getConstantRange(V2State, I.getType());
- ConstantRange R = A.binaryOp(cast<BinaryOperator>(&I)->getOpcode(), B);
+
+ auto *BO = cast<BinaryOperator>(&I);
+ ConstantRange R = ConstantRange::getEmpty(I.getType()->getScalarSizeInBits());
+ if (auto *OBO = dyn_cast<OverflowingBinaryOperator>(BO)) {
+ bool HasNUW = OBO->hasNoUnsignedWrap();
+ bool HasNSW = OBO->hasNoSignedWrap();
+ unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) |
+ (HasNSW ? OverflowingBinaryOperator::NoSignedWrap : 0);
----------------
dtcxzyw wrote:
Copied from `LazyValueInfoImpl::solveBlockValueBinaryOp`:
```suggestion
unsigned NoWrapKind = 0;
if (OBO->hasNoUnsignedWrap())
NoWrapKind |= OverflowingBinaryOperator::NoUnsignedWrap;
if (OBO->hasNoSignedWrap())
NoWrapKind |= OverflowingBinaryOperator::NoSignedWrap;
```
Do we need a helper `OverflowingBinaryOperator::getNoWrapKind()`?
https://github.com/llvm/llvm-project/pull/84470
More information about the llvm-commits
mailing list