This is an archive of the discontinued LLVM Phabricator instance.

[DAG] Peek through trunc when combining select into shifts.
ClosedPublic

Authored by deadalnix on Jun 1 2023, 11:29 AM.

Diff Detail

Event Timeline

deadalnix created this revision.Jun 1 2023, 11:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2023, 11:29 AM
deadalnix requested review of this revision.Jun 1 2023, 11:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2023, 11:29 AM
deadalnix updated this revision to Diff 527551.Jun 1 2023, 11:59 AM

This causes a regression in CodeGen/PowerPC/select_const.ll (at least in the no isel case).

foad added a comment.Jun 5 2023, 12:09 AM

A trunc can change the value of the shift amount, so how is it correct to peek through it?

Yes, we're going to need a KnownBits check to ensure we were truncating away known zero bits

deadalnix updated this revision to Diff 528381.Jun 5 2023, 5:13 AM

Check the truncate doesn't lose information.
Remove the zero extent case as it seems to only regress things.

RKSimon added inline comments.Jun 5 2023, 6:01 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
13184–13185

Please can you move this as an NFC pre-commit and then rebase the patch? Just to show that there are no changes to the logic in isTruncateOf.

deadalnix updated this revision to Diff 528460.Jun 5 2023, 8:36 AM

Rebase on top of an NFC that moves isTruncateOf.

deadalnix updated this revision to Diff 530856.Jun 13 2023, 4:07 AM

rebase again

nikic added inline comments.Jun 13 2023, 6:00 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
2489

Outdated comment about zext.

2495

isTruncateOf() handles truncates and some kind of weird setcc pattern. Do we need/want that pattern here? Is there test coverage for it?

deadalnix retitled this revision from [DAG] Peek through any trunc/zext when combining select into shifts. to [DAG] Peek through trunc when combining select into shifts..Jun 14 2023, 5:37 AM
deadalnix updated this revision to Diff 531298.Jun 14 2023, 6:12 AM

Rebase, add tests for setcc patterns in isTruncateOf.

deadalnix updated this revision to Diff 532816.Jun 20 2023, 1:14 AM

Rebase, ping?

nikic added inline comments.Jun 20 2023, 1:56 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
2500

if (Known.countMaxActiveBits() < Sel.getScalarValueSizeInBits()) or so?

deadalnix updated this revision to Diff 533385.Jun 21 2023, 1:53 PM

Use countMaxActiveBits

nikic accepted this revision.Jun 22 2023, 2:35 AM

LGTM

This revision is now accepted and ready to land.Jun 22 2023, 2:35 AM
This revision was landed with ongoing or failed builds.Jun 22 2023, 5:35 PM
This revision was automatically updated to reflect the committed changes.