This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] fold (add (add (xor a, -1), b), 1) -> (sub b, a)
ClosedPublic

Authored by deadalnix on Mar 2 2019, 6:39 AM.

Diff Detail

Event Timeline

deadalnix created this revision.Mar 2 2019, 6:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2019, 6:39 AM

Looks sane https://rise4fun.com/Alive/Nfiz
But looks like it's missed in instcombine too?
https://godbolt.org/z/UdEwql

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
2197–2198

Tests?

vector test?

It is interesting that instcombine doesn't do this. I would have expected it to be the case. Let me prepare a patch for it.

I made the patch for InstCombine: D58877

spatel added a comment.Mar 3 2019, 7:48 AM

If this pattern can emerge during legalization, then yes, we want a DAG combine for it. There's also a question raised in the IR version of the patch (D58877) about a reassociated version of this pattern. We don't have a dedicated reassociation pass for SDAG, so DAGCombine is responsible for handling that pattern too. Do we already have it, or should it be added too (as a separate DAG patch)?

All the pattern I submit in DAGCombiner are extracted from actual code -in this case libraries doing cryptography). I never encountered the vector version of this but I'm happy to add test cases for them if this is of interest.

deadalnix updated this revision to Diff 189846.Mar 8 2019, 5:21 AM

Rebase and regenerate tests introduced in rL355400

Please can you rebase after rL355699 ?

deadalnix updated this revision to Diff 189869.Mar 8 2019, 9:17 AM

Update to reflect change in tests (the vector test had an incorrect constant in it).

RKSimon accepted this revision.Mar 8 2019, 9:26 AM

LGTM

This revision is now accepted and ready to land.Mar 8 2019, 9:26 AM
This revision was automatically updated to reflect the committed changes.