Skip to content

Commit aac0790

Browse files
committed
[DivRemPairs] Do not freeze poisons that can't be undef
Per comments in DivRemPairs, the rewrite from %div = div %X, %Y %rem = rem %X, %Y to %div = div %X, %Y %.mul = mul %div, %Y %rem = sub %X, %mul is unsound when %X or %Y are undef. However, it is known to be sound if %X or %Y are poison but can't be undef, since both the pre- and post-rewrite %rem are `poison`. A comment in the pass listed a TODO for changing a usage of isGuaranteedNotToBeUndefOrPoison() in the pass to something that only detects undef. Such a function has been implemented since the time that TODO was written, but has not been used. Therefore, this commit updates DivRemPairs to use isGuaranteedNotToBeUndef() instead.
1 parent 1e9324a commit aac0790

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

llvm/lib/Transforms/Scalar/DivRemPairs.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,16 +381,15 @@ static bool optimizeDivRem(Function &F, const TargetTransformInfo &TTI,
381381
// %mul = mul %div, 1 // %mul = undef
382382
// %rem = sub %x, %mul // %rem = undef - undef = undef
383383
// If X is not frozen, %rem becomes undef after transformation.
384-
// TODO: We need a undef-specific checking function in ValueTracking
385-
if (!isGuaranteedNotToBeUndefOrPoison(X, nullptr, DivInst, &DT)) {
384+
if (!isGuaranteedNotToBeUndef(X, nullptr, DivInst, &DT)) {
386385
auto *FrX =
387386
new FreezeInst(X, X->getName() + ".frozen", DivInst->getIterator());
388387
DivInst->setOperand(0, FrX);
389388
Sub->setOperand(0, FrX);
390389
}
391390
// Same for Y. If X = 1 and Y = (undef | 1), %rem in src is either 1 or 0,
392391
// but %rem in tgt can be one of many integer values.
393-
if (!isGuaranteedNotToBeUndefOrPoison(Y, nullptr, DivInst, &DT)) {
392+
if (!isGuaranteedNotToBeUndef(Y, nullptr, DivInst, &DT)) {
394393
auto *FrY =
395394
new FreezeInst(Y, Y->getName() + ".frozen", DivInst->getIterator());
396395
DivInst->setOperand(1, FrY);

0 commit comments

Comments
 (0)