[llvm] [DAGCombiner] Narrow the integer source of sint_to_fp (PR #224242)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 17 02:15:49 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Harrison Hao (harrisonGPU)

<details>
<summary>Changes</summary>

Truncate the source of a `sint_to_fp` when it is known to fit in a narrower
type the target can convert from directly.
For example:
```
    sitofp (sext i32 %x to i64) to float
```
On AMDGPU this becomes a single `v_cvt_f32_i32` instead of the generic
i64 to f32 expansion.

Note: X86 marks i16 sint_to_fp as Custom, but SSE only supports conversion from
i32, so the custom lowering sign-extends i16 back to i32. Mark i16 as
undesirable to avoid a redundant movswl.

---

<sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>

---

Patch is 68.62 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/224242.diff


4 Files Affected:

- (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+29) 
- (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+1) 
- (modified) llvm/test/CodeGen/AMDGPU/int_to_fp_narrow_i64.ll (+161-761) 
- (modified) llvm/test/CodeGen/X86/fold-int-pow2-with-fmul-or-fdiv.ll (+4-4) 


``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index ac7222faedf14..b48cadde320db 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -20673,6 +20673,35 @@ SDValue DAGCombiner::visitSINT_TO_FP(SDNode *N) {
   if (SDValue FTrunc = foldFPToIntToFP(N, DL, DAG, TLI))
     return FTrunc;
 
+  // fold (sint_to_fp x) -> (sint_to_fp (trunc x)) when the value of x is known
+  // to fit in a narrower type the target can convert from directly.
+  LLVMContext &Ctx = *DAG.getContext();
+  unsigned ScalarBits = OpVT.getScalarSizeInBits();
+  unsigned SignificantBits = DAG.ComputeMaxSignificantBits(N0);
+  for (unsigned Bits = bit_ceil(SignificantBits); Bits < ScalarBits;
+       Bits *= 2) {
+    EVT NarrowVT = OpVT.changeElementType(Ctx, EVT::getIntegerVT(Ctx, Bits));
+
+    // Vector conversion the target has to unroll, or one it only supports by
+    // widening the operand back up, is not a win.
+    if (!hasOperation(ISD::SINT_TO_FP, NarrowVT) ||
+        !TLI.isTypeDesirableForOp(ISD::SINT_TO_FP, NarrowVT) ||
+        !TLI.isTruncateFree(N0, NarrowVT))
+      continue;
+
+    // Avoid creating an illegal vector type before type legalization.
+    if ((LegalTypes || OpVT.isVector()) && !TLI.isTypeLegal(NarrowVT))
+      continue;
+
+    // Avoid undoing target combines that widen vector integer to fp operands.
+    if (N0.getOpcode() == ISD::SIGN_EXTEND &&
+        NarrowVT == N0.getOperand(0).getValueType())
+      continue;
+
+    SDValue Trunc = DAG.getNode(ISD::TRUNCATE, DL, NarrowVT, N0);
+    return DAG.getNode(ISD::SINT_TO_FP, DL, VT, Trunc);
+  }
+
   // fold (sint_to_fp (trunc nsw x)) -> (sint_to_fp x)
   if (N0.getOpcode() == ISD::TRUNCATE && N0->getFlags().hasNoSignedWrap() &&
       TLI.isTypeDesirableForOp(ISD::SINT_TO_FP,
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 64a4a191e5881..6d374c6e3fb12 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -64308,6 +64308,7 @@ bool X86TargetLowering::isTypeDesirableForOp(unsigned Opc, EVT VT) const {
     case ISD::ZERO_EXTEND:
     case ISD::ANY_EXTEND:
     case ISD::MUL:
+    case ISD::SINT_TO_FP:
       return false;
     case ISD::SHL:
     case ISD::SRA:
diff --git a/llvm/test/CodeGen/AMDGPU/int_to_fp_narrow_i64.ll b/llvm/test/CodeGen/AMDGPU/int_to_fp_narrow_i64.ll
index 97959296858c4..29e7912b4f674 100644
--- a/llvm/test/CodeGen/AMDGPU/int_to_fp_narrow_i64.ll
+++ b/llvm/test/CodeGen/AMDGPU/int_to_fp_narrow_i64.ll
@@ -13,19 +13,10 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f16(ptr addrspace(1) %ou
 ; GFX6-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x9
 ; GFX6-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX6-NEXT:    s_ashr_i32 s2, s3, 31
-; GFX6-NEXT:    s_flbit_i32 s4, s2
-; GFX6-NEXT:    s_add_i32 s4, s4, -1
-; GFX6-NEXT:    s_mov_b32 s3, s2
-; GFX6-NEXT:    s_min_u32 s4, s4, 32
-; GFX6-NEXT:    s_lshl_b64 s[2:3], s[2:3], s4
-; GFX6-NEXT:    s_min_u32 s2, s2, 1
-; GFX6-NEXT:    s_or_b32 s2, s3, s2
 ; GFX6-NEXT:    v_cvt_f32_i32_e32 v0, s2
-; GFX6-NEXT:    s_sub_i32 s2, 32, s4
 ; GFX6-NEXT:    s_mov_b32 s3, 0xf000
-; GFX6-NEXT:    v_ldexp_f32_e64 v0, v0, s2
-; GFX6-NEXT:    v_cvt_f16_f32_e32 v0, v0
 ; GFX6-NEXT:    s_mov_b32 s2, -1
+; GFX6-NEXT:    v_cvt_f16_f32_e32 v0, v0
 ; GFX6-NEXT:    buffer_store_short v0, off, s[0:3], 0
 ; GFX6-NEXT:    s_endpgm
 ;
@@ -34,17 +25,8 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f16(ptr addrspace(1) %ou
 ; GFX8-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x24
 ; GFX8-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX8-NEXT:    s_ashr_i32 s2, s3, 31
-; GFX8-NEXT:    s_flbit_i32 s4, s2
-; GFX8-NEXT:    s_add_i32 s4, s4, -1
-; GFX8-NEXT:    s_mov_b32 s3, s2
-; GFX8-NEXT:    s_min_u32 s4, s4, 32
-; GFX8-NEXT:    s_lshl_b64 s[2:3], s[2:3], s4
-; GFX8-NEXT:    s_min_u32 s2, s2, 1
-; GFX8-NEXT:    s_or_b32 s2, s3, s2
 ; GFX8-NEXT:    v_cvt_f32_i32_e32 v0, s2
-; GFX8-NEXT:    s_sub_i32 s2, 32, s4
 ; GFX8-NEXT:    v_mov_b32_e32 v1, s1
-; GFX8-NEXT:    v_ldexp_f32 v0, v0, s2
 ; GFX8-NEXT:    v_cvt_f16_f32_e32 v2, v0
 ; GFX8-NEXT:    v_mov_b32_e32 v0, s0
 ; GFX8-NEXT:    flat_store_short v[0:1], v2
@@ -56,21 +38,8 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f16(ptr addrspace(1) %ou
 ; GFX11-TRUE16-NEXT:    v_mov_b32_e32 v1, 0
 ; GFX11-TRUE16-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX11-TRUE16-NEXT:    s_ashr_i32 s2, s3, 31
-; GFX11-TRUE16-NEXT:    s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
-; GFX11-TRUE16-NEXT:    s_cls_i32 s3, s2
-; GFX11-TRUE16-NEXT:    s_add_i32 s4, s3, -1
-; GFX11-TRUE16-NEXT:    s_mov_b32 s3, s2
-; GFX11-TRUE16-NEXT:    s_min_u32 s4, s4, 32
-; GFX11-TRUE16-NEXT:    s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
-; GFX11-TRUE16-NEXT:    s_lshl_b64 s[2:3], s[2:3], s4
-; GFX11-TRUE16-NEXT:    s_min_u32 s2, s2, 1
-; GFX11-TRUE16-NEXT:    s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
-; GFX11-TRUE16-NEXT:    s_or_b32 s2, s3, s2
+; GFX11-TRUE16-NEXT:    s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
 ; GFX11-TRUE16-NEXT:    v_cvt_f32_i32_e32 v0, s2
-; GFX11-TRUE16-NEXT:    s_sub_i32 s2, 32, s4
-; GFX11-TRUE16-NEXT:    s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
-; GFX11-TRUE16-NEXT:    v_ldexp_f32 v0, v0, s2
-; GFX11-TRUE16-NEXT:    s_delay_alu instid0(VALU_DEP_1)
 ; GFX11-TRUE16-NEXT:    v_cvt_f16_f32_e32 v0.l, v0
 ; GFX11-TRUE16-NEXT:    global_store_b16 v1, v0, s[0:1]
 ; GFX11-TRUE16-NEXT:    s_endpgm
@@ -81,21 +50,8 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f16(ptr addrspace(1) %ou
 ; GFX11-FAKE16-NEXT:    v_mov_b32_e32 v1, 0
 ; GFX11-FAKE16-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX11-FAKE16-NEXT:    s_ashr_i32 s2, s3, 31
-; GFX11-FAKE16-NEXT:    s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
-; GFX11-FAKE16-NEXT:    s_cls_i32 s3, s2
-; GFX11-FAKE16-NEXT:    s_add_i32 s4, s3, -1
-; GFX11-FAKE16-NEXT:    s_mov_b32 s3, s2
-; GFX11-FAKE16-NEXT:    s_min_u32 s4, s4, 32
-; GFX11-FAKE16-NEXT:    s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
-; GFX11-FAKE16-NEXT:    s_lshl_b64 s[2:3], s[2:3], s4
-; GFX11-FAKE16-NEXT:    s_min_u32 s2, s2, 1
-; GFX11-FAKE16-NEXT:    s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
-; GFX11-FAKE16-NEXT:    s_or_b32 s2, s3, s2
+; GFX11-FAKE16-NEXT:    s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
 ; GFX11-FAKE16-NEXT:    v_cvt_f32_i32_e32 v0, s2
-; GFX11-FAKE16-NEXT:    s_sub_i32 s2, 32, s4
-; GFX11-FAKE16-NEXT:    s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
-; GFX11-FAKE16-NEXT:    v_ldexp_f32 v0, v0, s2
-; GFX11-FAKE16-NEXT:    s_delay_alu instid0(VALU_DEP_1)
 ; GFX11-FAKE16-NEXT:    v_cvt_f16_f32_e32 v0, v0
 ; GFX11-FAKE16-NEXT:    global_store_b16 v1, v0, s[0:1]
 ; GFX11-FAKE16-NEXT:    s_endpgm
@@ -108,17 +64,8 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f16(ptr addrspace(1) %ou
 ; GFX701-NEXT:    s_lshr_b32 flat_scratch_hi, s12, 8
 ; GFX701-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX701-NEXT:    s_ashr_i32 s2, s3, 31
-; GFX701-NEXT:    s_flbit_i32 s4, s2
-; GFX701-NEXT:    s_add_i32 s4, s4, -1
-; GFX701-NEXT:    s_mov_b32 s3, s2
-; GFX701-NEXT:    s_min_u32 s4, s4, 32
-; GFX701-NEXT:    s_lshl_b64 s[2:3], s[2:3], s4
-; GFX701-NEXT:    s_min_u32 s2, s2, 1
-; GFX701-NEXT:    s_or_b32 s2, s3, s2
 ; GFX701-NEXT:    v_cvt_f32_i32_e32 v0, s2
-; GFX701-NEXT:    s_sub_i32 s2, 32, s4
 ; GFX701-NEXT:    v_mov_b32_e32 v1, s1
-; GFX701-NEXT:    v_ldexp_f32_e64 v0, v0, s2
 ; GFX701-NEXT:    v_cvt_f16_f32_e32 v2, v0
 ; GFX701-NEXT:    v_mov_b32_e32 v0, s0
 ; GFX701-NEXT:    flat_store_short v[0:1], v2
@@ -132,17 +79,8 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f16(ptr addrspace(1) %ou
 ; GFX803-NEXT:    s_lshr_b32 flat_scratch_hi, s12, 8
 ; GFX803-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX803-NEXT:    s_ashr_i32 s2, s3, 31
-; GFX803-NEXT:    s_flbit_i32 s4, s2
-; GFX803-NEXT:    s_add_i32 s4, s4, -1
-; GFX803-NEXT:    s_mov_b32 s3, s2
-; GFX803-NEXT:    s_min_u32 s4, s4, 32
-; GFX803-NEXT:    s_lshl_b64 s[2:3], s[2:3], s4
-; GFX803-NEXT:    s_min_u32 s2, s2, 1
-; GFX803-NEXT:    s_or_b32 s2, s3, s2
 ; GFX803-NEXT:    v_cvt_f32_i32_e32 v0, s2
-; GFX803-NEXT:    s_sub_i32 s2, 32, s4
 ; GFX803-NEXT:    v_mov_b32_e32 v1, s1
-; GFX803-NEXT:    v_ldexp_f32 v0, v0, s2
 ; GFX803-NEXT:    v_cvt_f16_f32_e32 v2, v0
 ; GFX803-NEXT:    v_mov_b32_e32 v0, s0
 ; GFX803-NEXT:    flat_store_short v[0:1], v2
@@ -154,16 +92,7 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f16(ptr addrspace(1) %ou
 ; GFX942-NEXT:    v_mov_b32_e32 v1, 0
 ; GFX942-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX942-NEXT:    s_ashr_i32 s2, s3, 31
-; GFX942-NEXT:    s_flbit_i32 s4, s2
-; GFX942-NEXT:    s_add_i32 s4, s4, -1
-; GFX942-NEXT:    s_mov_b32 s3, s2
-; GFX942-NEXT:    s_min_u32 s4, s4, 32
-; GFX942-NEXT:    s_lshl_b64 s[2:3], s[2:3], s4
-; GFX942-NEXT:    s_min_u32 s2, s2, 1
-; GFX942-NEXT:    s_or_b32 s2, s3, s2
 ; GFX942-NEXT:    v_cvt_f32_i32_e32 v0, s2
-; GFX942-NEXT:    s_sub_i32 s2, 32, s4
-; GFX942-NEXT:    v_ldexp_f32 v0, v0, s2
 ; GFX942-NEXT:    v_cvt_f16_f32_e32 v0, v0
 ; GFX942-NEXT:    global_store_short v1, v0, s[0:1]
 ; GFX942-NEXT:    s_endpgm
@@ -181,18 +110,9 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f32(ptr addrspace(1) %ou
 ; GFX6-NEXT:    s_mov_b32 s6, -1
 ; GFX6-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX6-NEXT:    s_ashr_i32 s2, s3, 31
-; GFX6-NEXT:    s_flbit_i32 s4, s2
-; GFX6-NEXT:    s_add_i32 s4, s4, -1
-; GFX6-NEXT:    s_mov_b32 s3, s2
-; GFX6-NEXT:    s_min_u32 s8, s4, 32
-; GFX6-NEXT:    s_lshl_b64 s[2:3], s[2:3], s8
-; GFX6-NEXT:    s_min_u32 s2, s2, 1
-; GFX6-NEXT:    s_or_b32 s2, s3, s2
 ; GFX6-NEXT:    v_cvt_f32_i32_e32 v0, s2
 ; GFX6-NEXT:    s_mov_b32 s4, s0
-; GFX6-NEXT:    s_sub_i32 s0, 32, s8
 ; GFX6-NEXT:    s_mov_b32 s5, s1
-; GFX6-NEXT:    v_ldexp_f32_e64 v0, v0, s0
 ; GFX6-NEXT:    buffer_store_dword v0, off, s[4:7], 0
 ; GFX6-NEXT:    s_endpgm
 ;
@@ -201,42 +121,21 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f32(ptr addrspace(1) %ou
 ; GFX8-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x24
 ; GFX8-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX8-NEXT:    s_ashr_i32 s2, s3, 31
-; GFX8-NEXT:    s_flbit_i32 s4, s2
-; GFX8-NEXT:    s_add_i32 s4, s4, -1
-; GFX8-NEXT:    s_mov_b32 s3, s2
-; GFX8-NEXT:    s_min_u32 s4, s4, 32
-; GFX8-NEXT:    s_lshl_b64 s[2:3], s[2:3], s4
-; GFX8-NEXT:    s_min_u32 s2, s2, 1
-; GFX8-NEXT:    s_or_b32 s2, s3, s2
 ; GFX8-NEXT:    v_cvt_f32_i32_e32 v2, s2
 ; GFX8-NEXT:    v_mov_b32_e32 v0, s0
-; GFX8-NEXT:    s_sub_i32 s0, 32, s4
 ; GFX8-NEXT:    v_mov_b32_e32 v1, s1
-; GFX8-NEXT:    v_ldexp_f32 v2, v2, s0
 ; GFX8-NEXT:    flat_store_dword v[0:1], v2
 ; GFX8-NEXT:    s_endpgm
 ;
 ; GFX11-LABEL: s_sint_to_fp_64_sign_bits_to_f32:
 ; GFX11:       ; %bb.0:
 ; GFX11-NEXT:    s_load_b128 s[0:3], s[4:5], 0x24
-; GFX11-NEXT:    v_mov_b32_e32 v1, 0
+; GFX11-NEXT:    v_mov_b32_e32 v0, 0
 ; GFX11-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX11-NEXT:    s_ashr_i32 s2, s3, 31
-; GFX11-NEXT:    s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
-; GFX11-NEXT:    s_cls_i32 s3, s2
-; GFX11-NEXT:    s_add_i32 s4, s3, -1
-; GFX11-NEXT:    s_mov_b32 s3, s2
-; GFX11-NEXT:    s_min_u32 s4, s4, 32
-; GFX11-NEXT:    s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
-; GFX11-NEXT:    s_lshl_b64 s[2:3], s[2:3], s4
-; GFX11-NEXT:    s_min_u32 s2, s2, 1
-; GFX11-NEXT:    s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
-; GFX11-NEXT:    s_or_b32 s2, s3, s2
-; GFX11-NEXT:    v_cvt_f32_i32_e32 v0, s2
-; GFX11-NEXT:    s_sub_i32 s2, 32, s4
-; GFX11-NEXT:    s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
-; GFX11-NEXT:    v_ldexp_f32 v0, v0, s2
-; GFX11-NEXT:    global_store_b32 v1, v0, s[0:1]
+; GFX11-NEXT:    s_delay_alu instid0(SALU_CYCLE_1)
+; GFX11-NEXT:    v_cvt_f32_i32_e32 v1, s2
+; GFX11-NEXT:    global_store_b32 v0, v1, s[0:1]
 ; GFX11-NEXT:    s_endpgm
 ;
 ; GFX701-LABEL: s_sint_to_fp_64_sign_bits_to_f32:
@@ -247,18 +146,9 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f32(ptr addrspace(1) %ou
 ; GFX701-NEXT:    s_lshr_b32 flat_scratch_hi, s12, 8
 ; GFX701-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX701-NEXT:    s_ashr_i32 s2, s3, 31
-; GFX701-NEXT:    s_flbit_i32 s4, s2
-; GFX701-NEXT:    s_add_i32 s4, s4, -1
-; GFX701-NEXT:    s_mov_b32 s3, s2
-; GFX701-NEXT:    s_min_u32 s4, s4, 32
-; GFX701-NEXT:    s_lshl_b64 s[2:3], s[2:3], s4
-; GFX701-NEXT:    s_min_u32 s2, s2, 1
-; GFX701-NEXT:    s_or_b32 s2, s3, s2
 ; GFX701-NEXT:    v_cvt_f32_i32_e32 v2, s2
 ; GFX701-NEXT:    v_mov_b32_e32 v0, s0
-; GFX701-NEXT:    s_sub_i32 s0, 32, s4
 ; GFX701-NEXT:    v_mov_b32_e32 v1, s1
-; GFX701-NEXT:    v_ldexp_f32_e64 v2, v2, s0
 ; GFX701-NEXT:    flat_store_dword v[0:1], v2
 ; GFX701-NEXT:    s_endpgm
 ;
@@ -270,18 +160,9 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f32(ptr addrspace(1) %ou
 ; GFX803-NEXT:    s_lshr_b32 flat_scratch_hi, s12, 8
 ; GFX803-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX803-NEXT:    s_ashr_i32 s2, s3, 31
-; GFX803-NEXT:    s_flbit_i32 s4, s2
-; GFX803-NEXT:    s_add_i32 s4, s4, -1
-; GFX803-NEXT:    s_mov_b32 s3, s2
-; GFX803-NEXT:    s_min_u32 s4, s4, 32
-; GFX803-NEXT:    s_lshl_b64 s[2:3], s[2:3], s4
-; GFX803-NEXT:    s_min_u32 s2, s2, 1
-; GFX803-NEXT:    s_or_b32 s2, s3, s2
 ; GFX803-NEXT:    v_cvt_f32_i32_e32 v2, s2
 ; GFX803-NEXT:    v_mov_b32_e32 v0, s0
-; GFX803-NEXT:    s_sub_i32 s0, 32, s4
 ; GFX803-NEXT:    v_mov_b32_e32 v1, s1
-; GFX803-NEXT:    v_ldexp_f32 v2, v2, s0
 ; GFX803-NEXT:    flat_store_dword v[0:1], v2
 ; GFX803-NEXT:    s_endpgm
 ;
@@ -291,16 +172,7 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f32(ptr addrspace(1) %ou
 ; GFX942-NEXT:    v_mov_b32_e32 v1, 0
 ; GFX942-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX942-NEXT:    s_ashr_i32 s2, s3, 31
-; GFX942-NEXT:    s_flbit_i32 s4, s2
-; GFX942-NEXT:    s_add_i32 s4, s4, -1
-; GFX942-NEXT:    s_mov_b32 s3, s2
-; GFX942-NEXT:    s_min_u32 s4, s4, 32
-; GFX942-NEXT:    s_lshl_b64 s[2:3], s[2:3], s4
-; GFX942-NEXT:    s_min_u32 s2, s2, 1
-; GFX942-NEXT:    s_or_b32 s2, s3, s2
 ; GFX942-NEXT:    v_cvt_f32_i32_e32 v0, s2
-; GFX942-NEXT:    s_sub_i32 s2, 32, s4
-; GFX942-NEXT:    v_ldexp_f32 v0, v0, s2
 ; GFX942-NEXT:    global_store_dword v1, v0, s[0:1]
 ; GFX942-NEXT:    s_endpgm
   %narrow = ashr i64 %in, 63
@@ -313,15 +185,14 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f64(ptr addrspace(1) %ou
 ; GFX6-LABEL: s_sint_to_fp_64_sign_bits_to_f64:
 ; GFX6:       ; %bb.0:
 ; GFX6-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x9
+; GFX6-NEXT:    s_mov_b32 s7, 0xf000
+; GFX6-NEXT:    s_mov_b32 s6, -1
 ; GFX6-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX6-NEXT:    s_ashr_i32 s2, s3, 31
 ; GFX6-NEXT:    v_cvt_f64_i32_e32 v[0:1], s2
-; GFX6-NEXT:    v_cvt_f64_u32_e32 v[2:3], s2
-; GFX6-NEXT:    s_mov_b32 s3, 0xf000
-; GFX6-NEXT:    s_mov_b32 s2, -1
-; GFX6-NEXT:    v_ldexp_f64 v[0:1], v[0:1], 32
-; GFX6-NEXT:    v_add_f64 v[0:1], v[0:1], v[2:3]
-; GFX6-NEXT:    buffer_store_dwordx2 v[0:1], off, s[0:3], 0
+; GFX6-NEXT:    s_mov_b32 s4, s0
+; GFX6-NEXT:    s_mov_b32 s5, s1
+; GFX6-NEXT:    buffer_store_dwordx2 v[0:1], off, s[4:7], 0
 ; GFX6-NEXT:    s_endpgm
 ;
 ; GFX8-LABEL: s_sint_to_fp_64_sign_bits_to_f64:
@@ -330,9 +201,6 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f64(ptr addrspace(1) %ou
 ; GFX8-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX8-NEXT:    s_ashr_i32 s2, s3, 31
 ; GFX8-NEXT:    v_cvt_f64_i32_e32 v[0:1], s2
-; GFX8-NEXT:    v_cvt_f64_u32_e32 v[2:3], s2
-; GFX8-NEXT:    v_ldexp_f64 v[0:1], v[0:1], 32
-; GFX8-NEXT:    v_add_f64 v[0:1], v[0:1], v[2:3]
 ; GFX8-NEXT:    v_mov_b32_e32 v2, s0
 ; GFX8-NEXT:    v_mov_b32_e32 v3, s1
 ; GFX8-NEXT:    flat_store_dwordx2 v[2:3], v[0:1]
@@ -341,15 +209,11 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f64(ptr addrspace(1) %ou
 ; GFX11-LABEL: s_sint_to_fp_64_sign_bits_to_f64:
 ; GFX11:       ; %bb.0:
 ; GFX11-NEXT:    s_load_b128 s[0:3], s[4:5], 0x24
+; GFX11-NEXT:    v_mov_b32_e32 v2, 0
 ; GFX11-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX11-NEXT:    s_ashr_i32 s2, s3, 31
-; GFX11-NEXT:    s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
+; GFX11-NEXT:    s_delay_alu instid0(SALU_CYCLE_1)
 ; GFX11-NEXT:    v_cvt_f64_i32_e32 v[0:1], s2
-; GFX11-NEXT:    v_cvt_f64_u32_e32 v[2:3], s2
-; GFX11-NEXT:    v_ldexp_f64 v[0:1], v[0:1], 32
-; GFX11-NEXT:    s_delay_alu instid0(VALU_DEP_1)
-; GFX11-NEXT:    v_add_f64 v[0:1], v[0:1], v[2:3]
-; GFX11-NEXT:    v_mov_b32_e32 v2, 0
 ; GFX11-NEXT:    global_store_b64 v2, v[0:1], s[0:1]
 ; GFX11-NEXT:    s_endpgm
 ;
@@ -362,12 +226,9 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f64(ptr addrspace(1) %ou
 ; GFX701-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX701-NEXT:    s_ashr_i32 s2, s3, 31
 ; GFX701-NEXT:    v_cvt_f64_i32_e32 v[0:1], s2
-; GFX701-NEXT:    v_cvt_f64_u32_e32 v[2:3], s2
-; GFX701-NEXT:    v_mov_b32_e32 v4, s0
-; GFX701-NEXT:    v_mov_b32_e32 v5, s1
-; GFX701-NEXT:    v_ldexp_f64 v[0:1], v[0:1], 32
-; GFX701-NEXT:    v_add_f64 v[0:1], v[0:1], v[2:3]
-; GFX701-NEXT:    flat_store_dwordx2 v[4:5], v[0:1]
+; GFX701-NEXT:    v_mov_b32_e32 v2, s0
+; GFX701-NEXT:    v_mov_b32_e32 v3, s1
+; GFX701-NEXT:    flat_store_dwordx2 v[2:3], v[0:1]
 ; GFX701-NEXT:    s_endpgm
 ;
 ; GFX803-LABEL: s_sint_to_fp_64_sign_bits_to_f64:
@@ -379,9 +240,6 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f64(ptr addrspace(1) %ou
 ; GFX803-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX803-NEXT:    s_ashr_i32 s2, s3, 31
 ; GFX803-NEXT:    v_cvt_f64_i32_e32 v[0:1], s2
-; GFX803-NEXT:    v_cvt_f64_u32_e32 v[2:3], s2
-; GFX803-NEXT:    v_ldexp_f64 v[0:1], v[0:1], 32
-; GFX803-NEXT:    v_add_f64 v[0:1], v[0:1], v[2:3]
 ; GFX803-NEXT:    v_mov_b32_e32 v2, s0
 ; GFX803-NEXT:    v_mov_b32_e32 v3, s1
 ; GFX803-NEXT:    flat_store_dwordx2 v[2:3], v[0:1]
@@ -390,14 +248,11 @@ define amdgpu_kernel void @s_sint_to_fp_64_sign_bits_to_f64(ptr addrspace(1) %ou
 ; GFX942-LABEL: s_sint_to_fp_64_sign_bits_to_f64:
 ; GFX942:       ; %bb.0:
 ; GFX942-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
-; GFX942-NEXT:    v_mov_b32_e32 v4, 0
+; GFX942-NEXT:    v_mov_b32_e32 v2, 0
 ; GFX942-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX942-NEXT:    s_ashr_i32 s2, s3, 31
 ; GFX942-NEXT:    v_cvt_f64_i32_e32 v[0:1], s2
-; GFX942-NEXT:    v_ldexp_f64 v[0:1], v[0:1], 32
-; GFX942-NEXT:    v_cvt_f64_u32_e32 v[2:3], s2
-; GFX942-NEXT:    v_add_f64 v[0:1], v[0:1], v[2:3]
-; GFX942-NEXT:    global_store_dwordx2 v4, v[0:1], s[0:1]
+; GFX942-NEXT:    global_store_dwordx2 v2, v[0:1], s[0:1]
 ; GFX942-NEXT:    s_endpgm
   %narrow = ashr i64 %in, 63
   %result = sitofp i64 %narrow to double
@@ -409,24 +264,13 @@ define amdgpu_kernel void @s_sint_to_fp_sext_i16_to_f16(ptr addrspace(1) %out, i
 ; GFX6-LABEL: s_sint_to_fp_sext_i16_to_f16:
 ; GFX6:       ; %bb.0:
 ; GFX6-NEXT:    s_load_dword s0, s[4:5], 0xb
+; GFX6-NEXT:    s_mov_b32 s3, 0xf000
+; GFX6-NEXT:    s_mov_b32 s2, -1
 ; GFX6-NEXT:    s_waitcnt lgkmcnt(0)
-; GFX6-NEXT:    s_bfe_i64 s[0:1], s[0:1], 0x100000
-; GFX6-NEXT:    s_xor_b32 s2, s0, s1
-; GFX6-NEXT:    s_flbit_i32 s3, s1
-; GFX6-NEXT:    s_ashr_i32 s2, s2, 31
-; GFX6-NEXT:    s_add_i32 s2, s2, 32
-; GFX6-NEXT:    s_add_i32 s3, s3, -1
-; GFX6-NEXT:    s_min_u32 s2, s3, s2
-; GFX6-NEXT:    s_lshl_b64 s[0:1], s[0:1], s2
-; GFX6-NEXT:    s_min_u32 s0, s0, 1
-; GFX6-NEXT:    s_or_b32 s0, s1, s0
+; GFX6-NEXT:    s_sext_i32_i16 s0, s0
 ; GFX6-NEXT:    v_cvt_f32_i32_e32 v0, s0
-; GFX6-NEXT:    s_sub_i32 s2, 32, s2
 ; GFX6-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x9
-; GFX6-NEXT:    s_mov_b32 s3, 0xf000
-; GFX6-NEXT:    v_ldexp_f32_e64 v0, v0, s2
 ; GFX6-NEXT:    v_cvt_f16_f32_e32 v0, v0
-; GFX6-NEXT:    s_mov_b32 s2, -1
 ; GFX6-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX6-NEXT:    buffer_store_short v0, off, s[0:3], 0
 ; GFX6-NEXT:    s_endpgm
@@ -435,20 +279,9 @@ define amdgpu_kernel void @s_sint_to_fp_sext_i16_to_f16(ptr addrspace(1) %out, i
 ; GFX8:       ; %bb.0:
 ; GFX8-NEXT:    s_load_dword s0, s[4:5], 0x2c
 ; GFX8-NEXT:    s_waitcnt lgkmcnt(0)
-; GFX8-NEXT:    s_bfe_i64 s[0:1], s[0:1], 0x100000
-; GFX8-NEXT:    s_xor_b32 s2, s0, s1
-; GFX8-NEXT:    s_flbit_i32 s3, s1
-; GFX8-NEXT:    s_ashr_i32 s2, s2, 31
-; GFX8-NEXT:   ...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/224242


More information about the llvm-commits mailing list