This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] [AArch64] Fold G_PTRTOINT(G_CONSTANT)
Needs ReviewPublic

Authored by andcarminati on Dec 19 2022, 6:22 AM.

Details

Summary
Fold the following pattern:

    %0:_(p0) = G_CONSTANT i64 0
    %1:_(s64) = G_PTRTOINT %0:_(p0)
    %2 = COPY %1(s64)

Into:
    %0:_(s64) = G_CONSTANT i64 0
    %1 = COPY %0(s64)

Diff Detail

Event Timeline

andcarminati created this revision.Dec 19 2022, 6:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 19 2022, 6:22 AM
andcarminati requested review of this revision.Dec 19 2022, 6:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 19 2022, 6:22 AM
arsenm added a subscriber: arsenm.Dec 19 2022, 6:34 AM

Where are these coming from? I thought we directly emitted pointer constants now?

andcarminati edited the summary of this revision. (Show Details)Dec 19 2022, 6:52 AM
andcarminati edited the summary of this revision. (Show Details)

Where are these coming from? I thought we directly emitted pointer constants now?

Well, we have this folding implemented in our development branch (custom target) and we think it is interesting for AArch64 too.

andcarminati edited the summary of this revision. (Show Details)Dec 19 2022, 7:00 AM

Where are these coming from? I thought we directly emitted pointer constants now?

I think this is special cased for ConstantPointerNull

llvm/include/llvm/Target/GlobalISel/Combine.td
514

Should be able to just use replaceInstWithConstant

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
2095–2098

We already have a matchConstantOp, but that checks for a specific constant. Should have another generic one that checks for any constant

Maybe should have the constant folding MIRBuilder do this too

Where are these coming from? I thought we directly emitted pointer constants now?

Well, we have this folding implemented in our development branch (custom target) and we think it is interesting for AArch64 too.

How much of a code size improvement did you see with this change?

The patch was updated to the main branch.

Some background: we are upstreaming this pattern through the AArch64 because the target backend that we are developing in our company was not upstreamed yet. About usability, we observed that this pattern is being matched and can impact the final code.