Page MenuHomePhabricator

[GlobalISel] Avoid making G_PTR_ADD with nullptr
Needs ReviewPublic

Authored by mbrkusanin on Fri, Sep 4, 6:04 AM.

Details

Reviewers
arsenm
foad
Summary

When the first operand is a null pointer we can avoid making a G_PTR_ADD and
make a G_INTTOPTR with the offset operand.
This helps us avoid making add with 0 later on for targets such as AMDGPU.

Diff Detail

Event Timeline

mbrkusanin created this revision.Fri, Sep 4, 6:04 AM
mbrkusanin requested review of this revision.Fri, Sep 4, 6:04 AM
arsenm added a comment.Fri, Sep 4, 6:46 AM

This is probably wrong for non integral pointers. Why not do this as a combine later? We need to start recognizing G_PTRADD (constant) + constant anyway to handle lowered LDS addresses

foad added inline comments.Fri, Sep 4, 7:12 AM
llvm/test/CodeGen/AArch64/GlobalISel/translate-gep.ll
11 ↗(On Diff #289930)

Can you avoid generating this unused constant in the first place?

  • Reimplemented as a AMDGPU GICombineRule.
arsenm added inline comments.Wed, Sep 16, 6:13 AM
llvm/lib/Target/AMDGPU/AMDGPUCombine.td
40

ptr_add

40–45

This should go in the generic combiner

llvm/lib/Target/AMDGPU/AMDGPUPreLegalizerCombiner.cpp
45

Should not construct a local MachineIRBuilder

llvm/test/CodeGen/AMDGPU/GlobalISel/combine-add-nullptr.mir
52–53

Can simplify these out of the test

56

Should add vector test