This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] fold add/sub with bool operand based on target's boolean contents
ClosedPublic

Authored by spatel on Jan 29 2019, 10:49 AM.

Details

Summary

I noticed that we are missing this canonicalization in IR:
rL352515
...and then realized that we don't get this right in SDAG either, so this has to be fixed first regardless of what we choose to do in IR.

The existing fold was limited to scalars and using the wrong predicate to guard the transform. We have a boolean contents TLI query that can be used to decide which direction to fold.

This may eventually lead back to the problems/question in:
https://bugs.llvm.org/show_bug.cgi?id=40486
...but it makes no difference to that yet.

Diff Detail

Repository
rL LLVM

Event Timeline

spatel created this revision.Jan 29 2019, 10:49 AM
efriedma added inline comments.Jan 29 2019, 5:50 PM
test/CodeGen/PowerPC/select_const.ll
268–269 ↗(On Diff #184121)

This looks like a missing target-independent pattern; we're ending up with something like "42 - (cond & 1)" instead of "42 + cond".

spatel marked an inline comment as done.Jan 30 2019, 6:29 AM
spatel added inline comments.
test/CodeGen/PowerPC/select_const.ll
268–269 ↗(On Diff #184121)

Yes, we're missing a generic combine here, but I thought we had the 1 you mentioned. Ie, if I saw it correctly while glancing at it the first time, this requires an AssertSext to uncover.

I'll have a closer look to avoid this, but I figured the other diffs were more realistic, so we might want to commit this patch first if it looks reasonable.

efriedma added inline comments.Jan 30 2019, 11:16 AM
test/CodeGen/PowerPC/select_const.ll
268–269 ↗(On Diff #184121)

If the issue is actually just a missing combine for "X - (Y & 1)", where Y is a 0/-1 value, I'm fine with temporarily regressing it. But please confirm the DAG actually looks like that.

spatel updated this revision to Diff 184380.Jan 30 2019, 2:57 PM

Patch updated:
The missing fold that was shown in the previous rev should be fixed here:
rL352680 (I added some extra tests to verify that was behaving as expected)

Interestingly, that actually caught my motivating cases for x86 and AArch in the earlier rev of this patch. So now we only show diffs for PPC tests, and those are all improvements. These tests also exist for x86, but there are no diffs there...I didn't step through all of those, but it looks like custom hacks to form LEA instructions mask any underlying changes.

efriedma accepted this revision.Feb 6 2019, 2:19 PM

LGTM

This revision is now accepted and ready to land.Feb 6 2019, 2:19 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2019, 9:43 AM