Canonicalize
((x + C1) & C2) --> ((x & C2) + C1) ((x + C1) ^ C2) --> ((x ^ C2) + C1) ((x + C1) | C2) --> ((x | C2) + C1)
for suitable constants C1 and C2.
Alive2 proofs: add, or --> or, add
add, xor --> xor, add
add, and --> and, add
Paths
| Differential D131142
[InstCombine] Canonicalize "and, add", "or, add", "xor, add" ClosedPublic Authored by emgullufsen on Aug 3 2022, 10:24 PM.
Details Summary Canonicalize ((x + C1) & C2) --> ((x & C2) + C1) ((x + C1) ^ C2) --> ((x ^ C2) + C1) ((x + C1) | C2) --> ((x | C2) + C1) for suitable constants C1 and C2. Alive2 proofs: add, or --> or, add
Diff Detail
Event Timelineemgullufsen retitled this revision from [InstCombine] Canonicalize ((x + C1) & C2) --> ((x & C2) + C1) ((x + C1) & C2) --> ((x & C2) + C1) ((x + C1) & C2) --> ((x & C2) + C1) for suitable constants C1 and C2. to [InstCombine] .Aug 3 2022, 10:36 PM emgullufsen retitled this revision from [InstCombine] to [InstCombine] Canonicalize "and, add", "or, add", "xor, add". emgullufsen removed a parent revision: D130075: [InstCombine] Try not to demand low order bits for Add.Aug 9 2022, 9:41 PM emgullufsen added a parent revision: D130075: [InstCombine] Try not to demand low order bits for Add. Comment Actions Looks good overall.
Comment Actions We need to keep nsw/nuw for add I think.
Comment Actions
Agreed, good point. Comment Actions This patch now does not affect integer-round-up-pow2-alignment.ll (since those changes merged via rGf82c55fa082711f520a7359393b483956b69bf08). So, the NFC changes (changes of variable names) that update_test_checks would make don't have to be addressed at this time (I don't think). I did pull those NFC changes to this test out anyway as D132564, but as said I don't think this needs to be messed with just now. emgullufsen removed a parent revision: D130075: [InstCombine] Try not to demand low order bits for Add.Aug 24 2022, 9:30 AM Comment Actions This seems right, but can you verify with Alive2 and add the links to the patch summary. Comment Actions
Oh shoot I had meant to include alive2 proofs - sorry for that (and thank you for or/xor proofs) - will get patch summary updated. This revision is now accepted and ready to land.Aug 26 2022, 10:49 AM This revision was landed with ongoing or failed builds.Aug 26 2022, 11:07 AM Closed by commit rGd2f110c693c8: [InstCombine] Canonicalize "and, add", "or, add", "xor, add" (authored by emgullufsen). · Explain Why This revision was automatically updated to reflect the committed changes. reames added a reverting change: rGc58791c286e0: Revert "[InstCombine] Canonicalize "and, add", "or, add", "xor, add"".Aug 26 2022, 11:19 AM This revision is now accepted and ready to land.Aug 26 2022, 11:28 AM Comment Actions Sorry for the failed test - I ran update_test_checks against test/Transforms/InstCombine/freeze.ll, Comment Actions To confirm, you just missed updating a test, right? This revision is now accepted and ready to land.Aug 26 2022, 1:17 PM Comment Actions
Yes I just missed updating a test that I should have noticed, that actually caused bot failure. But freeze.ll seems to be the only one I missed - check-llvm results look good now. Comment Actions Thanks for reverting @reames - when you have a second maybe you could please have a look over this updated patch? Comment Actions
No need. I reverted because of a broken test, if that's been fixed, your LGTM stands. Comment Actions
Cool I see - I didn't think I needed to ask for review from reverting dev from Developer Policy, but just wanted to be sure I guess. Thanks again to you and to @spatel for help with proofs and review. Will be more careful with tests in the future. Closed by commit rGeb1e2b39978c: [InstCombine] Canonicalize "and, add", "or, add", "xor, add" (authored by emgullufsen). · Explain WhyAug 26 2022, 2:23 PM This revision was automatically updated to reflect the committed changes.
Comment Actions
Sorry to miss provisioning for carrying through nsw/nuw flags before, I am preparing tests/patch to fix this and will add as reviewer.
Revision Contents
Diff 449878 llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/and-xor-or.ll
llvm/test/Transforms/InstCombine/integer-round-up-pow2-alignment.ll
llvm/test/Transforms/InstCombine/or.ll
llvm/test/Transforms/InstCombine/sub.ll
|
clang-format not found in user’s local PATH; not linting file.