[AArch64][CostModel] Detects that {extract,insert}-element at lane 0 has the same...
authorMingming Liu <mingmingl@google.com>
Tue, 21 Jun 2022 20:38:30 +0000 (13:38 -0700)
committerMingming Liu <mingmingl@google.com>
Fri, 9 Sep 2022 16:47:30 +0000 (09:47 -0700)
commit8aa800614bf65f8db7b8293d514719e6921abe16
tree1e7a9ebf8a5b5e727851ee220828ea890a5705f5
parent4d50a392401c0d34a21c77529a2f3b9f9568339a
[AArch64][CostModel] Detects that {extract,insert}-element at lane 0 has the same cost as the other lane for vector instructions in the IR.

Currently, {extract,insert}-element has zero cost at lane 0 [1]. However, there is a cost (by fmov instruction [2], or ext/ins instruction) to move values from SIMD registers to GPR registers, when the element is used explicitly as integers.

See https://godbolt.org/z/faPE1nTn8, when fmov is generated for d* register -> x* register conversion.

Implementation-wise, add a private method `AArch64TTIImpl::getVectorInstrCostHelper` as a helper function. This way, instruction-based method could share the core logic (e.g.,
returning zero cost if type is legalized to scalar).

[1] https://github.com/llvm/llvm-project/blob/2cf320d41ed708679e01eeeb93f58d6c5c88ba7a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp#L1853
[2] https://github.com/llvm/llvm-project/blob/2cf320d41ed708679e01eeeb93f58d6c5c88ba7a/llvm/lib/Target/AArch64/AArch64InstrInfo.td#L8150-L8157

Differential Revision: https://reviews.llvm.org/D128302
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h
llvm/test/Analysis/CostModel/AArch64/kryo-inseltpoison.ll
llvm/test/Analysis/CostModel/AArch64/kryo.ll
llvm/test/Analysis/CostModel/AArch64/sve-insert-extract.ll
llvm/test/Transforms/LICM/AArch64/extract-element.ll