[MemoryBuiltins][FIX] Adjust index type size properly wrt. AS casts
authorJohannes Doerfert <johannes@jdoerfert.de>
Tue, 1 Feb 2022 20:32:33 +0000 (14:32 -0600)
committerJohannes Doerfert <johannes@jdoerfert.de>
Tue, 8 Feb 2022 02:19:19 +0000 (20:19 -0600)
commit29c8ebad10b4c349a185438fed52e08426d603e1
tree093ad4427c367010284e6c11d1f19b75adbcdc9e
parent5aa3af3fcb014145ab315090bd3cbea00bea0038
[MemoryBuiltins][FIX] Adjust index type size properly wrt. AS casts

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.

Fixes #53559.

Differential Revision: https://reviews.llvm.org/D118727
llvm/include/llvm/Analysis/MemoryBuiltins.h
llvm/lib/Analysis/MemoryBuiltins.cpp
llvm/test/Transforms/InstCombine/builtin-dynamic-object-size.ll