This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Implement some binary reassociations, G_ADD for now
ClosedPublic

Authored by aemerson on May 9 2023, 3:19 PM.

Details

Summary
- (op (op X, C1), C2) -> (op X, (op C1, C2))
- (op (op X, C1), Y) -> (op (op X, Y), C1)

Some code duplication with the G_PTR_ADD reassociations unfortunately but no
easy way to avoid it that I can see.

Diff Detail

Event Timeline

aemerson created this revision.May 9 2023, 3:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2023, 3:19 PM
aemerson requested review of this revision.May 9 2023, 3:19 PM

@arsenm The AMDGPU/GlobalISel/regbankselect-amdgcn.s.buffer.load.ll test is failing but trying to run update_mir_test_checks.py fails with some error. Can you take a look to see if it's an issue with the test?

paquette added inline comments.May 9 2023, 3:24 PM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
4517

might as well just return false here if !C1 to save a level of indentation

4530

maybe pull the MRI.hasOneNonDBGUse(Op00) in here and then we don't need the second if?

llvm/test/CodeGen/AArch64/GlobalISel/prelegalizer-combiner-binop-reassoc.mir
5
aemerson added inline comments.May 9 2023, 7:55 PM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
4517

I actually left it like this to prepare for future reassociations that don't need C1 to match.

4530

Sure.

aemerson updated this revision to Diff 520888.May 9 2023, 7:57 PM

Move a check.

tschuett added inline comments.
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
4519

Did you hoist C2out of the if for future work?

aemerson added inline comments.May 10 2023, 8:03 PM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
4519

Actually it seems I misread the existing combines, these can be early exits.

aemerson updated this revision to Diff 521204.May 10 2023, 8:41 PM
  • Don't hoist a declaration.
  • Rename Op00 like names to LHS/RHS ones.
tschuett added inline comments.May 10 2023, 11:18 PM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
4519

Could you turn the auto's into bool's? C1 and C2 are know only for documentation?

aemerson updated this revision to Diff 521217.May 11 2023, 12:15 AM

@arsenm ping. Do you know why the AMDGPU test doesn't work with update_mir_test_checks?

@arsenm ping. Do you know why the AMDGPU test doesn't work with update_mir_test_checks?

What is the error? update_mir_test_checks is pretty buggy with multiple run lines and multiple checks. I sometimes need to delete individual run lines to get it t work

llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.s.buffer.load.ll
5019–5023

This result is worse so we'd ideally have something regbank aware

aemerson updated this revision to Diff 528159.Jun 3 2023, 4:16 PM

Disable these combines for AMDGPU targets with the hook.

arsenm added inline comments.Jun 4 2023, 4:03 AM
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
13441

Go with return true and leave the fixme? The diff was overall better I think

aemerson updated this revision to Diff 528594.Jun 5 2023, 3:12 PM

Enable for AMDGPU.

arsenm accepted this revision.Jun 8 2023, 4:29 PM
This revision is now accepted and ready to land.Jun 8 2023, 4:29 PM
This revision was landed with ongoing or failed builds.Jun 8 2023, 9:38 PM
This revision was automatically updated to reflect the committed changes.