[PATCH] D120371: [instcombine] Generalize one-compare rule from foldAllocaCmp for noalias calls
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 23 01:07:23 PST 2022
nikic added a comment.
This looks basically right to me.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1035
+ bool captured(const Use *U) override {
+ NumCmps++;
+ if (NumCmps == 1)
----------------
Can you please add an explicit check here that this is an icmp user? I guess you omitted the check on the premise that you have a known icmp user, so if you see a single capture it must be that icmp. That may be true, but the fact that we also have certain non-capturing icmps makes the reasoning here very non-obvious.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:6053
+ if (isKnownNonZero(Op0, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT) ||
+ isKnownNonZero(Op1, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT)) {
+ if (isNoAliasCall(UO0))
----------------
`malloc(4) + 1 == 1` would be a hidden null check. Though from a quick look, we would not recognize `malloc(4) + 1` as non-zero.
`malloc(4) < 4` would be another possibility, making use of malloc alignment guarantees to perform a hidden null pointer check.
Not sure what to do about these, it's rather contrived...
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120371/new/
https://reviews.llvm.org/D120371
More information about the llvm-commits
mailing list