LVI gives us a ConstantRange which we can use to determine if the
results of div and shr instructions will always be zero. Similarly, we
can determine if one side of max/min instructions will always be
returned.
Details
Diff Detail
Event Timeline
See https://llvm.org/docs/TestingGuide.html#precommit-workflow-for-tests and the following section for testing requirements.
TBH the entire patch makes very little sense to me.
llvm/include/llvm/IR/ConstantRange.h | ||
---|---|---|
283 | I think you re-invented the icmp() method here. CR1.icmp(ICmpInst::ICMP_UGT, CR2) etc is how you're supposed to write these. | |
llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp | ||
578 | How does your code differ from the existing getPredicateAt() check above? The tests you added already fold without your change. |
TBH the entire patch makes very little sense to me.
Thanks for the review. I think the main problem is that I was unaware of some key ConstantRange and LVI functionality, namely icmp() and getPredicateAt(), as you pointed out. Additionally, when I ported this patch from LLVM 15 to main I missed that some of the opportunities to remove instructions I was catching in this patch had already been caught. However, I ran my tests in this patch on main and found missed opportunities to remove sdiv, ashr, and lshr instructions.
I am re-working the patch to remove the duplication and follow the existing methods (e.g. the code to eliminate udiv's in expandUDivOrURem() using ConstantRange::icmp()).
I'll update this revision in a day or 2, including a fix for the build failure.
llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp | ||
---|---|---|
1098 | LVI should be able to determine that this value is constant by itself -- does using LVI->getConstant(SDI, SDI) give the desired result? |
I think you re-invented the icmp() method here. CR1.icmp(ICmpInst::ICMP_UGT, CR2) etc is how you're supposed to write these.