This is an archive of the discontinued LLVM Phabricator instance.

[ConstFold] Constant fold load through invariant group intrinsics
AbandonedPublic

Authored by aeubanks on Apr 20 2021, 11:23 PM.

Details

Reviewers
pcc
rnk
Summary

Loads should be able to look through invariant group intrinsics when
we're trying to constant fold.

This fixes some major code size regressions due to RTTI when
-fstrict-vtable-pointers is turned on.

Since invariant group intrinsics can't be constants,
ConstantFoldLoadFromConstPtr had to be changed to accept Values instead
of Constants. A majority of this patch is fixing up functions to work
with a Value instead of a Constant.

SymbolicallyEvaluateGEP has a new option to strip pointers specifically
for load constant folding. We can't strip all-zero GEPs since we walk
GlobalVariable constants using GEP indices, so introduce a new pointer
stripping type. We need this to simplify GEPs that have an operand that
derive from an invariant group intrinsic. Otherwise we can never see
that the GEP pointer operand could be a constant GlobalVariable.

The new pointer stripping mode also looks through local aliases to local
aliasees, fixing devirtualization with MSVC RTTI.

Diff Detail

Event Timeline

aeubanks created this revision.Apr 20 2021, 11:23 PM
aeubanks requested review of this revision.Apr 20 2021, 11:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2021, 11:23 PM
nikic added a subscriber: nikic.Apr 21 2021, 1:35 PM

This looks like a pretty serious layering violation, in that constants folding is now no longer folding constants. LLVM pretty strictly separates ConstantFold (folding instructions with all-constant operands), InstSimplify (folding instructions to a constant or existing instruction) and InstCombine (folding arbitrarily). This patch blurs the line between ConstantFold and InstSimplify.

llvm/test/Transforms/InstCombine/invariant.group-load.ll
4

Please prefer update_test_checks.py unless there is some specific reason not to use it (e.g. huge output). Also, if this already folds with just -instsimplify, please test it there instead.

aeubanks planned changes to this revision.Apr 21 2021, 1:45 PM

This looks like a pretty serious layering violation, in that constants folding is now no longer folding constants. LLVM pretty strictly separates ConstantFold (folding instructions with all-constant operands), InstSimplify (folding instructions to a constant or existing instruction) and InstCombine (folding arbitrarily). This patch blurs the line between ConstantFold and InstSimplify.

That makes sense.
So instead I should add a SimplifyFold to llvm::SimplifyInstruction?

aeubanks abandoned this revision.Apr 22 2021, 1:16 PM

abandoning in favor of D101103 and D101100