[InstCombine] Teach alloca replacement to handle `addrspacecast`
authorMichael Liao <michael.hliao@gmail.com>
Thu, 23 Mar 2023 20:29:14 +0000 (16:29 -0400)
committerMichael Liao <michael.hliao@gmail.com>
Tue, 11 Apr 2023 15:47:37 +0000 (11:47 -0400)
commit72fc08a5412ec7ee7f0b904926db16cd86c1f876
tree28ac6caa5290ebc64216e70925ac53145ea7668c
parent2a0c0849747425b570561e6bd9869843131a880d
[InstCombine] Teach alloca replacement to handle `addrspacecast`

- As the address space cast may not be valid on a specific target,
  `addrspacecast` is not handled when an `alloca` is able to be replaced
  with the source of memcpy/memmove. This patch addresses that by
  querying a target hook on whether that address space cast is valid.
  For example, on most GPU targets, the cast from a global pointer to a
  generic pointer is valid.
- If that cast is allowedd (by querying `isValidAddrSpaceCast`), the
  replacement is enhanced to handle that `addrspacecast` as well.

Reviewed By: yaxunl

Differential Revision: https://reviews.llvm.org/D147025
llvm/include/llvm/Analysis/TargetTransformInfo.h
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
llvm/include/llvm/CodeGen/BasicTTIImpl.h
llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
llvm/lib/Analysis/TargetTransformInfo.cpp
llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.h
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/AMDGPU/memcpy-from-constant.ll
llvm/test/Transforms/InstCombine/ptr-replace-alloca.ll