Detect a recurrence that monotonically increases with mul.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
| llvm/lib/Analysis/ValueTracking.cpp | ||
|---|---|---|
| 2452–2453 | I think the matchSimpleRecurrence() check should be higher, e.g. PN->getNumIncomingValues() == 2 is already part of it. | |
| 2453 | I'd rename R/L to Start and Step. | |
| 2460 | Why does this exclude C = 1? {1,*,2}<nuw> is still non-zero. The one value is important for inequality, but here we're checking for non-zero. | |
| 2463 | Again, this isOne() check looks unnecessary to me. | |
| llvm/test/Analysis/ValueTracking/monotonic-phi.ll | ||
| 91 | Why is this or needed? | |
| 109 | Why does this return false? Isn't this supposed to be a negative test case, due to lack of nuw/nsw? | |
| llvm/lib/Analysis/ValueTracking.cpp | ||
|---|---|---|
| 2452–2453 | Yep, you are right. I will move it up. | |
| 2453 | Yep, I will rename them. | |
| 2460 | You are right!!! We are checking non-zero. I will update it. | |
| 2463 | Yep, I will update it. | |
| llvm/test/Analysis/ValueTracking/monotonic-phi.ll | ||
| 91 | We do not need it. I will remove it. | |
| 109 | Yep, it is negative test case due to lack of nuw/nsw. It could be better to check CHECK: ret i1 %cmp. I will update it. | |
This looks good to me, but I think needs a couple more tests:
- Positive test for nuw instead of nsw.
- Negative test for zero start value.
- Negative test for negative multiply. (We can't really test zero multiply, as it will get folded away.)
- Negative test for negative start value -- alternatively, you can slightly extend this patch and split the start value check between add and mul: Add requires strictly positive start, but for mul non-zero is sufficient, I believe.
| llvm/lib/Analysis/ValueTracking.cpp | ||
|---|---|---|
| 2454 | Style suggestion: I would write this using m_APInt matchers, which allows you to avoid some of the nesting: Value *Start, *Step;
const APInt *StartC, *StepC;
if (Q.IIQ.UseInstrInfo && matchSimpleRecurrence(PN, BO, Start, Step) &&
match(Start, m_APInt(StartC)) && match(Step, m_APInt(StepC)) &&
StartC->isStrictlyPositive()) {
...
} | |
| llvm/test/Analysis/ValueTracking/monotonic-phi.ll | ||
| 109 | Ah, I guess I misread a CHECK-NOT as CHECK here? I've regenerated the check lines for this test in https://github.com/llvm/llvm-project/commit/b7aae9fab14540ad3b4ccda8a5f3a7284f404e63, so you can generate the expected output using llvm/utils/update_test_checks.py. | |
Thanks @nikic If possible, can you also review https://reviews.llvm.org/D98422 please? I think it could also be ready to merge.
I think the matchSimpleRecurrence() check should be higher, e.g. PN->getNumIncomingValues() == 2 is already part of it.