Page MenuHomePhabricator

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

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



[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

Unit TestsFailed

160 msx64 debian > ORC-x86_64-linux.TestCases/Linux/x86-64::trivial-cxa-atexit.S
Script: -- : 'RUN: at line 3'; /var/lib/buildkite-agent/builds/llvm-project/build/./bin/clang -m64 -c -o /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/test/orc/X86_64LinuxConfig/TestCases/Linux/x86-64/Output/trivial-cxa-atexit.S.tmp /var/lib/buildkite-agent/builds/llvm-project/compiler-rt/test/orc/TestCases/Linux/x86-64/trivial-cxa-atexit.S
130 msx64 debian > ORC-x86_64-linux.TestCases/Linux/x86-64::trivial-static-initializer.S
Script: -- : 'RUN: at line 7'; /var/lib/buildkite-agent/builds/llvm-project/build/./bin/clang -m64 -c -o /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/test/orc/X86_64LinuxConfig/TestCases/Linux/x86-64/Output/trivial-static-initializer.S.tmp /var/lib/buildkite-agent/builds/llvm-project/compiler-rt/test/orc/TestCases/Linux/x86-64/trivial-static-initializer.S
140 msx64 debian > ORC-x86_64-linux.TestCases/Linux/x86-64::trivial-tls.S
Script: -- : 'RUN: at line 1'; /var/lib/buildkite-agent/builds/llvm-project/build/./bin/clang -m64 -c -o /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/test/orc/X86_64LinuxConfig/TestCases/Linux/x86-64/Output/trivial-tls.S.tmp /var/lib/buildkite-agent/builds/llvm-project/compiler-rt/test/orc/TestCases/Linux/x86-64/trivial-tls.S

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


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.