This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombine] Refactor ReduceLoadWidth
ClosedPublic

Authored by samparker on Nov 3 2017, 6:13 AM.

Details

Summary

visitAND attempts to narrow the width of extending loads that are then masked off. ReduceLoadWidth already exists for a similar purpose and handles shifts, so I've moved the code to handle AND nodes there.

Diff Detail

Repository
rL LLVM

Event Timeline

samparker created this revision.Nov 3 2017, 6:13 AM
samparker retitled this revision from [CodeGen] Refactor DAG combine ReduceLoadWidth to [DAGCombine] Refactor ReduceLoadWidth.Nov 6 2017, 1:25 AM
fhahn added a subscriber: fhahn.Nov 6 2017, 1:54 AM

Removing the unneeded LoadedVT seems like a straight-forward NFC and I think it would be worth to submit it for review as an isolated change, as it does not seem related to moving some code to ReduceLoadWidth.

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
7969 ↗(On Diff #121466)

If we support extension using AND, I think we should also update the comment here.

7999 ↗(On Diff #121466)

I am probably missing something, but I am not sure if I see the real benefit of moving this code here. It seems the visitAND was the right place to do it, without requiring additional checks. However, it seems like there is potential to simplify the code in visitAND

Hi Florian,

Thanks for the comments, I will revert the LoadedVT change.

cheers,
sam

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
7999 ↗(On Diff #121466)

Both visitAND and ReduceLoadWidth contained essentially the same code to generate the new load, so it seems reasonable to me to contain this logic within the sensibly named function. In D39604 I also wish to directly use this function to combine ANDs and hopefully it can more helpful when anyone else wants to do similar.

samparker updated this revision to Diff 121703.Nov 6 2017, 2:31 AM
samparker edited the summary of this revision. (Show Details)

Removed the unrelated API change and updated the description of ReduceLoadWidth.

Hi Florian,

Do you have any other suggestions?

cheers

Looks like a reasonable refactor to me helping with D39604. Adding Simon & Eli as reviewers as I think they know the area better then myself.

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
7999 ↗(On Diff #121466)

Ah yes, there is some shared code to generated the new load, I missed initially! ReduceLoadWidth also contains a few more legality checks.

efriedma added inline comments.Nov 16 2017, 11:58 AM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
8026 ↗(On Diff #121703)

Could this block of code be simplified? As long as you set ExtType and ExtVT correctly, I think the rest of the checks already exist in some form, by analogy to the transforms for ISD::SIGN_EXTEND_IN_REG.

samparker updated this revision to Diff 123311.Nov 17 2017, 3:24 AM

Removed most of the checks performed on the load, leaving just the SEXT check.

samparker added inline comments.Nov 22 2017, 2:19 AM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
8026 ↗(On Diff #121703)

Thanks Eli, indeed most of the checks that performed again.

fhahn accepted this revision.Nov 27 2017, 2:29 AM

Thanks Sam, looks good to me. Please wait a day or two with committing, to give others a chance to raise additional concerns.

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
8034 ↗(On Diff #123311)

IIRC your first version of the patch removed to unneeded LoadedVT argument. I think this would be a worthwhile simplification to get in as NFC independently.

This revision is now accepted and ready to land.Nov 27 2017, 2:29 AM
RKSimon edited edge metadata.Nov 27 2017, 2:51 AM

Very minor comment

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
8031 ↗(On Diff #123311)

use bool here - we typically only use auto for casts

This revision was automatically updated to reflect the committed changes.

@fhahn @RKSimon @eli.friedman I made some small changes before committing, could someone please check them out? My development branch only had x86, Arm and Aarch64 targets built and so when I went to run my pre-commit tests, some were failing for AMDGPU and NVPTX. The issues were that even though some checks are duplicated, I have an early return in the new block which still requires those checks. Also I had missed how any_extend nodes are combined, so I re-added some code that was lost during the refactor.

efriedma edited edge metadata.Nov 30 2017, 11:40 AM

I'm still kind of concerned that this is messier than it needs to be. I guess I'll try experimenting a bit.