This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] Add logic `or` fold
ClosedPublic

Authored by MehrHeidar on Dec 2 2021, 1:51 PM.

Details

Diff Detail

Event Timeline

MehrHeidar created this revision.Dec 2 2021, 1:51 PM
MehrHeidar requested review of this revision.Dec 2 2021, 1:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2021, 1:51 PM
MehrHeidar edited the summary of this revision. (Show Details)Dec 3 2021, 6:51 AM
MehrHeidar updated this revision to Diff 391646.Dec 3 2021, 7:45 AM
MehrHeidar added reviewers: spatel, foad.
foad added a comment.Dec 3 2021, 8:06 AM

Looks fine to me but I will defer to @spatel.

spatel added inline comments.Dec 3 2021, 8:19 AM
llvm/lib/Analysis/InstructionSimplify.cpp
2231–2232

This is more like the folds at lines 2205 / 2213, right? If there are 2 commutative ops, then we are handling 4 distinct patterns.

And that means there should be 8 tests after we account for the swapped operands handled by the caller.

lebedev.ri retitled this revision from Add logic `or` fold to [InstSimplify] Add logic `or` fold .Dec 3 2021, 8:46 AM
MehrHeidar updated this revision to Diff 391663.Dec 3 2021, 9:40 AM

Add more commuted version of test cases.

MehrHeidar marked an inline comment as done.Dec 3 2021, 9:42 AM
MehrHeidar added inline comments.
llvm/lib/Analysis/InstructionSimplify.cpp
2231–2232

Thank you!
I added 5 more test cases for the rest of commuted versions.

spatel added inline comments.Dec 3 2021, 11:03 AM
llvm/lib/Analysis/InstructionSimplify.cpp
2229–2230

The code comment doesn't line up with the match logic. We always match the 'not' of A, so there shouldn't be a ~B here. There should be 4 lines in this list to make it symmetric with the other comments in this function.

llvm/test/Transforms/InstSimplify/or.ll
956

I think the tests are covering all the possibilities, but (similar to my previous comment) I'd prefer that we keep the 'not' on 'A' only, so it's easier to see how things are moving around in these comments/tests.

MehrHeidar updated this revision to Diff 391719.Dec 3 2021, 1:10 PM
MehrHeidar marked an inline comment as done.

Change the test cases and format of the comments to be more consistent with existing ones.

MehrHeidar marked 2 inline comments as done.Dec 3 2021, 2:44 PM
MehrHeidar added inline comments.
llvm/lib/Analysis/InstructionSimplify.cpp
2229–2230

I did change the comments to 4 lines and only A is not in the comments to match with the logic in code.

llvm/test/Transforms/InstSimplify/or.ll
956

I changed the test cases based on your suggestions; it totally make sense to follow same rule across the tests.
Thanks.

spatel accepted this revision.Dec 3 2021, 3:13 PM

LGTM - thanks! See inline for one very minor comment.

llvm/lib/Analysis/InstructionSimplify.cpp
2229

One more tiny nit - the 'X' in all of these formulas is the first operand of the 'or', but this set of formulas is showing 'X' as the second operand. That is, the inner 'or' that includes the 'not A' operand should be on the left side and the 'A ^ B' should be on the right to match what the code does.

This revision is now accepted and ready to land.Dec 3 2021, 3:13 PM
MehrHeidar marked 3 inline comments as done.Dec 4 2021, 12:05 PM
MehrHeidar added inline comments.
llvm/lib/Analysis/InstructionSimplify.cpp
2229

Thank you!
Right, I changed the order of or and xor in the comments to match the code.

This revision was automatically updated to reflect the committed changes.
MehrHeidar marked an inline comment as done.