Page MenuHomePhabricator

[InstCombine] Fold ptrtoint(gep null) with a variable index
ClosedPublic

Authored by arichardson on Sep 22 2021, 6:59 AM.

Details

Summary

[InstCombine] Fold ptrtoint(gep i8 null, x) -> x

This commit is the InstCombine follow-up to the previous constant-folding
change that enables noticeable optimizations for CHERI-enabled targets.

Depends on D110245

Diff Detail

Event Timeline

arichardson created this revision.Sep 22 2021, 6:59 AM
arichardson requested review of this revision.Sep 22 2021, 6:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 22 2021, 6:59 AM

I think the right way to view this fold is a special case of ptrtoint (gep p, o) - ptrtoint (gep p, o2), which is handled in OptimizePointerDifference(). This case is the special case where p = null and o2 = 0. Looking at that fold a) we support non-integral pointers, so I'd say it's fine to support them in all these folds as well and b) for the case where the GEP has one use, there are no limits on the number of variable offsets. This makes sense, because this arithmetic is happening anyway, GEPs just pretend they are simpler than they really are.

Rather than manually expanding the calculation, you can use EmitGEPOffset().

Use EmitGEPOffset, drop InstSimplify baseline

nikic accepted this revision.Sep 24 2021, 11:53 AM

LGTM

This revision is now accepted and ready to land.Sep 24 2021, 11:53 AM
This revision was landed with ongoing or failed builds.Sep 28 2021, 9:58 AM
This revision was automatically updated to reflect the committed changes.