Definitionally a non-zero power of 2 will only have 1 bit set so this
is a freebee.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Where in InstSimplify should it go? Looking around there didn't seem any fitting place.
I think you can add it to the ctpop handling in simplifyUnaryIntrinsic in llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | ||
---|---|---|
623–627 ↗ | (On Diff #490198) | Should this be in simplifyIntrinsic? |
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | ||
---|---|---|
623–627 ↗ | (On Diff #490198) |
Moved. |
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
5893 | Why change the parameter? The arg type must match the call return type for ctpop, so it shouldn't make a difference for this patch. If there's some other transform where it makes a difference, we could adjust it later? | |
5931–5932 | Remove the "Maybe better..." statement because we can't do that in InstSimplify (can't create new instructions here). But that should happen in InstCombine if it's not already done there. |
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
5895 | Any particular reason for this change? It doesn't look like you make use of it (note that Call->getType() == Op0->getType() below). |
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
5895 |
Didn't know that was guranteed, fixed. | |
5931–5932 |
Is this change needed at all then? Would just knownpow2 -> icmp ne 0 in InstCombine be better? But can do regardless. One thing, assuming we keep this AND add InstCombine change. Should I duplicate the test file or just add instcombine as a second pass in the current tests? |
LGTM
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
5931–5932 | It's a trade-off, and I'm not sure which way is better in this case. It's nice to make InstSimplify stronger because other passes (like EarlyCSE and GVN) use this as an analysis. But you're correct that it's also good to consolidate related folds. I don't think there's a real compile-time concern either way since ctpop should be too rare to make any difference to overall compile-time. If you want to add the fold for known-pow2-or-zero to instcombine, add those tests to InstCombine rather than here. There shouldn't be a need to duplicate the ones that are already handled here. The regression tests are meant to be minimal, so we don't want to run multiple/different passes here. |
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
5931–5932 |
Got it & Thanks! Quick question about protocol when a code change is accepted but the test patch isn't. Is it assumed that NFC test changes are okay to just push in that case or should I wait on separate approval there? |
Why change the parameter? The arg type must match the call return type for ctpop, so it shouldn't make a difference for this patch. If there's some other transform where it makes a difference, we could adjust it later?