diff options
author | Noah Goldstein <goldstein.w.n@gmail.com> | 2023-05-09 18:04:41 -0500 |
---|---|---|
committer | Noah Goldstein <goldstein.w.n@gmail.com> | 2023-05-09 19:11:21 -0500 |
commit | 2647547ee44f509a34ff9709b63bd7603ca59f5d (patch) | |
tree | c0f8d4833a77e66159e4d3c768b3993f9354f708 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 448bd59e18721e5357a37f080051db87cc3a4448 (diff) | |
download | llvm-2647547ee44f509a34ff9709b63bd7603ca59f5d.zip llvm-2647547ee44f509a34ff9709b63bd7603ca59f5d.tar.gz llvm-2647547ee44f509a34ff9709b63bd7603ca59f5d.tar.bz2 |
Re-revert "[ValueTracking] Use knownbits interface for determining if `div`/`rem` are safe to speculate"
Seems to be causing a bug in CorrelatedValuePropegation. Reverting
while the issue is investigated.
This reverts commit 6c667abf3294d61e4fbe1238e1755c79f7547f1b.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 6f6a16c..385fe42 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -6099,34 +6099,31 @@ bool llvm::isSafeToSpeculativelyExecuteWithOpcode( default: return true; case Instruction::UDiv: - case Instruction::URem: + case Instruction::URem: { + // x / y is undefined if y == 0. + const APInt *V; + if (match(Inst->getOperand(1), m_APInt(V))) + return *V != 0; + return false; + } case Instruction::SDiv: case Instruction::SRem: { - // x / y is undefined if y == 0 or y is poison. - const DataLayout &DL = Inst->getModule()->getDataLayout(); - if (!isGuaranteedNotToBePoison(Inst->getOperand(1), AC, CtxI, DT) || - !isKnownNonZero(Inst->getOperand(1), DL, /*Depth*/ 0, AC, CtxI, DT)) + // x / y is undefined if y == 0 or x == INT_MIN and y == -1 + const APInt *Numerator, *Denominator; + if (!match(Inst->getOperand(1), m_APInt(Denominator))) + return false; + // We cannot hoist this division if the denominator is 0. + if (*Denominator == 0) return false; - - // Unsigned case only needs to avoid denominator == 0 or poison. - if (Opcode == Instruction::UDiv || Opcode == Instruction::URem) - return true; - - // x s/ y is also undefined if x == INT_MIN and y == -1 - KnownBits KnownDenominator = - computeKnownBits(Inst->getOperand(1), DL, /*Depth*/ 0, AC, CtxI, DT); - // It's safe to hoist if the denominator is not 0 or -1. - if (!KnownDenominator.Zero.isZero()) + if (!Denominator->isAllOnes()) return true; - - // At this point denominator may be -1. It is safe to hoist as - // long we know that the numerator is neither poison nor INT_MIN. - if (!isGuaranteedNotToBePoison(Inst->getOperand(0), AC, CtxI, DT)) - return false; - KnownBits KnownNumerator = - computeKnownBits(Inst->getOperand(0), DL, /*Depth*/ 0, AC, CtxI, DT); - return !KnownNumerator.getSignedMinValue().isMinSignedValue(); + // At this point we know that the denominator is -1. It is safe to hoist as + // long we know that the numerator is not INT_MIN. + if (match(Inst->getOperand(0), m_APInt(Numerator))) + return !Numerator->isMinSignedValue(); + // The numerator *might* be MinSignedValue. + return false; } case Instruction::Load: { const LoadInst *LI = dyn_cast<LoadInst>(Inst); |