AMDGPU: Broadcast scalar boolean to vector boolean explicitly
authorRuiling Song <ruiling.song@amd.com>
Thu, 16 Sep 2021 15:04:39 +0000 (23:04 +0800)
committerRuiling Song <ruiling.song@amd.com>
Thu, 30 Sep 2021 02:15:01 +0000 (10:15 +0800)
commit52785989e95db15f5021f095198f821772d3d656
tree8a56ec1fea366aa7168a8ca511e80e443fbbf921
parent01641f665f5a3f94fc9e2bba598b5a65a6a7bd01
AMDGPU: Broadcast scalar boolean to vector boolean explicitly

This is used to fix wrong code generation of s_add_co_select_user in
test/CodeGen/AMDGPU/expand-scalar-carry-out-select-user.ll

  s_addc_u32 s4, s6, 0
  s_cselect_b64 vcc, 1, 0    <-- vcc set as 0x1 if SCC==1
  v_mov_b32_e32 v1, s4
  s_cmp_gt_u32 s6, 31
  v_cndmask_b32_e32 v1, 0, v1, vcc

If the s_addc_u32 set SCC, then we will get value 0x1 in VCC.
The v_cndmask will do per thread selection with VCC as condition
register. As VCC only gets the first bit being set, only the first
thread/lane in destination register can get correct result if the
very first lane is active. In fact, we should broadcast the value to all
active lanes of the final register.

The idea here is doing this broadcast to vector boolean explicitly
instead of lowering it into a COPY from SCC which would be interpreted as
selecting between 0/1.

This is used to replace D109754.

Reviewed-by: foad, alex-t
Differential Revision: https://reviews.llvm.org/D109889
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
llvm/test/CodeGen/AMDGPU/expand-scalar-carry-out-select-user.ll