[PATCH] D44102: Teach CorrelatedValuePropagation to reduce the width of udiv/urem instructions.

Sanjoy Das via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 5 14:45:27 PST 2018


sanjoy added a comment.

In https://reviews.llvm.org/D44102#1027656, @jlebar wrote:

> Disappointingly, this doesn't work for simple cases where you mask the divisor:
>
>   %b = and i64 %a, 65535
>   %div = udiv i64 %b, 42
>   


This is a little surprising to me -- on a first glance it looks like `LazyValueInfoImpl::solveBlockValueBinaryOp` should be doing the right thing here. But I dug a bit deeper and it looks like `getPredicateAt` calls `getValueAt` which only looks at guards and assumes (and never calls `solveBlockValueBinaryOp`)?  I have a hunch that using the `getConstantRange` call will "fix" this issue, though `getPredicateAt` definitely should be not weaker than calling `getConstantRange` and inferring the predicate manually.



================
Comment at: llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp:457
+        SDI->getType(), APInt::getAllOnesValue(Width).zext(OrigWidth));
+    if (all_of(SDI->operands(), [&](Value *Operand) {
+          return LVI->getPredicateAt(ICmpInst::ICMP_ULE, Operand, Max, SDI) ==
----------------
Instead of making multiple queries, how about using `LazyValueInfo::getConstantRange` instead?


https://reviews.llvm.org/D44102





More information about the llvm-commits mailing list