[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
Paths
| Differential D110247
[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 Depends on D110245
Diff Detail
Event TimelineComment Actions 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(). arichardson edited parent revisions, added: D110245: [ConstantFolding] Fold ptrtoint(gep i8 null, x) -> x; removed: D110246: [InstSimplify][InstCombine] Fold ptrtoint(gep i8 null, x) -> x.Sep 24 2021, 1:47 AM 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 Closed by commit rGebb3dc08339c: [InstCombine] Fold ptrtoint(gep i8 null, x) -> x (authored by arichardson). · Explain Why This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 375625 llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/ptrtoint-nullgep.ll
|