AMDGPU: Use isLiteralConstantLike to check whether the operand could ever be literal
authorChangpeng Fang <Changpeng.Fang@amd.com>
Thu, 31 Mar 2022 15:06:31 +0000 (08:06 -0700)
committerChangpeng Fang <Changpeng.Fang@amd.com>
Thu, 31 Mar 2022 15:06:31 +0000 (08:06 -0700)
commit1711020c3769d38e146c2c116376a2255630613a
treeaf172f8ea73c89206a7c3781292ecbd4db34c99a
parent0a460416e6ba8047175b0fe1c72eef1713b0cb0b
AMDGPU: Use isLiteralConstantLike to check whether the operand could ever be literal

Summary:
  To compute the size of a VALU/SALU instruction, we need to check whether an operand
could ever be literal. Previously isLiteralConstant was used, which missed cases
like global variables or external symbols. These misses lead to under-estimation of
the instruction size and branch offset, and thus incorrectly skip the necessary branch
relaxation when the branch offset is actually greater than what the branch bits can hold.
In this work, we use isLiteralConstantLike to check the operands. It maybe conservative,
but it is safe.

Reviewers: arsenm

Differential Revision: https://reviews.llvm.org/D122778
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
llvm/lib/Target/AMDGPU/SIInstructions.td
llvm/test/CodeGen/AMDGPU/literal-constant-like-operand-instruction-size.ll [new file with mode: 0644]