[PATCH] D99069: [ValueTracking] Handle increasing mul recurrence in isKnownNonZero()
JinGu Kang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 22 11:53:56 PDT 2021
jaykang10 added inline comments.
================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:2459
if (ConstantInt *C = dyn_cast<ConstantInt>(Start)) {
if (!C->isZero() && !C->isNegative()) {
+ BinaryOperator *BO = nullptr;
----------------
nikic wrote:
> I think the matchSimpleRecurrence() check should be higher, e.g. `PN->getNumIncomingValues() == 2` is already part of it.
Yep, you are right. I will move it up.
================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:2461
+ BinaryOperator *BO = nullptr;
+ Value *R = nullptr, *L = nullptr;
+ if (Q.IIQ.UseInstrInfo && matchSimpleRecurrence(PN, BO, R, L)) {
----------------
nikic wrote:
> I'd rename R/L to Start and Step.
Yep, I will rename them.
================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:2468
+ return true;
+ if (BO->getOpcode() == Instruction::Mul && !C->isOne() &&
+ (BO->hasNoUnsignedWrap() || BO->hasNoSignedWrap()) &&
----------------
nikic wrote:
> 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.
You are right!!! We are checking non-zero. I will update it.
================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:2471
+ !StepCst->isNegative() && !StepCst->isZero() &&
+ !StepCst->isOne())
+ return true;
----------------
nikic wrote:
> Again, this isOne() check looks unnecessary to me.
Yep, I will update it.
================
Comment at: llvm/test/Analysis/ValueTracking/monotonic-phi.ll:61
+exit:
+ %add = or i8 %A, %r
+ %cmp = icmp eq i8 %add, 0
----------------
nikic wrote:
> Why is this or needed?
We do not need it. I will remove it.
================
Comment at: llvm/test/Analysis/ValueTracking/monotonic-phi.ll:79
+ %cmp = icmp eq i8 %add, 0
+ ; CHECK-NOT: ret i1 false
+ ret i1 %cmp
----------------
nikic wrote:
> Why does this return false? Isn't this supposed to be a negative test case, due to lack of `nuw`/`nsw`?
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.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D99069/new/
https://reviews.llvm.org/D99069
More information about the llvm-commits
mailing list