This is an archive of the discontinued LLVM Phabricator instance.

[MemoryBuiltins][FIX] Adjust index type size properly wrt. AS casts
ClosedPublic

Authored by jdoerfert on Feb 1 2022, 12:39 PM.

Details

Summary

Use existing functionality to strip constant offsets that works well
with AS casts and avoids the code duplication.

Since we strip AS casts during the computation of the offset we also
need to adjust the APInt properly to avoid mismatches in the bit width.
This code ensures the caller of compute sees APInts that match the
index type size of the value passed to compute, not the value result
of the strip pointer cast.

Diff Detail

Event Timeline

jdoerfert created this revision.Feb 1 2022, 12:39 PM
jdoerfert requested review of this revision.Feb 1 2022, 12:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2022, 12:39 PM
Herald added a subscriber: wdng. · View Herald Transcript
jdoerfert updated this revision to Diff 405065.Feb 1 2022, 12:42 PM

Fix comments

jdoerfert added inline comments.Feb 1 2022, 12:50 PM
llvm/lib/Analysis/MemoryBuiltins.cpp
588

Here, and elsewhere, we could probably give up only on the problematic part (offset vs size).

arsenm added inline comments.Feb 1 2022, 4:56 PM
llvm/lib/Analysis/MemoryBuiltins.cpp
578–583

There are several flavors of stripPointerCasts. Why isn't this using stripAndAccumulateConstantOffsets?

jdoerfert updated this revision to Diff 405330.Feb 2 2022, 10:09 AM

Use existing strip and accumulate

jdoerfert updated this revision to Diff 405366.Feb 2 2022, 10:56 AM

Remove assertion that does not hold (non-constant GEPs can exist)

arsenm accepted this revision.Feb 2 2022, 10:59 AM
This revision is now accepted and ready to land.Feb 2 2022, 10:59 AM
nikic added inline comments.Feb 2 2022, 11:03 AM
llvm/lib/Analysis/MemoryBuiltins.cpp
612

Constant GEPs can have constant expression offsets, which will not be stripped.

jdoerfert marked an inline comment as done.Feb 2 2022, 1:35 PM
jdoerfert added inline comments.
llvm/lib/Analysis/MemoryBuiltins.cpp
612

Good point. I'll remove the assertion, nothing we can do with those otherwise.

jdoerfert updated this revision to Diff 405427.Feb 2 2022, 1:37 PM
jdoerfert marked an inline comment as done.

remove constant expr case and assert

jdoerfert edited the summary of this revision. (Show Details)Feb 2 2022, 1:37 PM
jdoerfert updated this revision to Diff 405521.Feb 2 2022, 10:03 PM

Re-introduce the former bit width adjustment. This passes all unit tests that
the strip change alone failed.

jdoerfert edited the summary of this revision. (Show Details)Feb 2 2022, 10:03 PM
arsenm added a comment.Feb 3 2022, 8:56 AM

Missing tests?

jdoerfert updated this revision to Diff 406464.Feb 7 2022, 7:42 AM

Add check lines

jdoerfert updated this revision to Diff 406466.Feb 7 2022, 7:45 AM

Add test to correct (=latest) version of the patch

arsenm added inline comments.Feb 7 2022, 3:13 PM
llvm/test/Transforms/InstCombine/builtin-dynamic-object-size.ll
175 ↗(On Diff #406466)

doesn't cover the special case constantexpr case?

jdoerfert updated this revision to Diff 406633.Feb 7 2022, 3:38 PM

Add second test with constexpr gep & as cast

arsenm accepted this revision.Feb 7 2022, 3:59 PM
This revision was landed with ongoing or failed builds.Feb 7 2022, 6:20 PM
This revision was automatically updated to reflect the committed changes.