[llvm] r370099 - DAG: computeNumSignBits for MUL

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 27 12:05:33 PDT 2019


Author: arsenm
Date: Tue Aug 27 12:05:33 2019
New Revision: 370099

URL: http://llvm.org/viewvc/llvm-project?rev=370099&view=rev
Log:
DAG: computeNumSignBits for MUL

Copied directly from the IR version.

Most of the testcases I've added for this are somewhat problematic
because they really end up testing the yet to be implemented version
for MUL_I24/MUL_U24.

Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
    llvm/trunk/test/CodeGen/AMDGPU/computeNumSignBits-mul.ll

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=370099&r1=370098&r2=370099&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Tue Aug 27 12:05:33 2019
@@ -3715,6 +3715,18 @@ unsigned SelectionDAG::ComputeNumSignBit
     Tmp = ComputeNumSignBits(Op.getOperand(0), Depth+1);
     if (Tmp == 1) return 1;  // Early out.
     return std::min(Tmp, Tmp2)-1;
+  case ISD::MUL: {
+    // The output of the Mul can be at most twice the valid bits in the inputs.
+    unsigned SignBitsOp0 = ComputeNumSignBits(Op.getOperand(0), Depth + 1);
+    if (SignBitsOp0 == 1)
+      break;
+    unsigned SignBitsOp1 = ComputeNumSignBits(Op.getOperand(1), Depth + 1);
+    if (SignBitsOp1 == 1)
+      break;
+    unsigned OutValidBits =
+        (VTBits - SignBitsOp0 + 1) + (VTBits - SignBitsOp1 + 1);
+    return OutValidBits > VTBits ? 1 : VTBits - OutValidBits + 1;
+  }
   case ISD::TRUNCATE: {
     // Check if the sign bits of source go down as far as the truncated value.
     unsigned NumSrcBits = Op.getOperand(0).getScalarValueSizeInBits();

Modified: llvm/trunk/test/CodeGen/AMDGPU/computeNumSignBits-mul.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/computeNumSignBits-mul.ll?rev=370099&r1=370098&r2=370099&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/computeNumSignBits-mul.ll (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/computeNumSignBits-mul.ll Tue Aug 27 12:05:33 2019
@@ -7,7 +7,7 @@ define i16 @num_sign_bits_mul_i48_0(i8 %
 ; GFX9-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
 ; GFX9-NEXT:    v_mul_i32_i24_sdwa v0, sext(v0), sext(v1) dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:BYTE_0 src1_sel:BYTE_0
 ; GFX9-NEXT:    v_mul_i32_i24_sdwa v1, sext(v2), sext(v3) dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:BYTE_0 src1_sel:BYTE_0
-; GFX9-NEXT:    v_mul_lo_u32 v0, v0, v1
+; GFX9-NEXT:    v_mul_i32_i24_e32 v0, v0, v1
 ; GFX9-NEXT:    s_setpc_b64 s[30:31]
   %A = sext i8 %X to i48
   %B = sext i8 %Y to i48
@@ -24,19 +24,10 @@ define i16 @num_sign_bits_mul_i48_1(i8 %
 ; GFX9-LABEL: num_sign_bits_mul_i48_1:
 ; GFX9:       ; %bb.0:
 ; GFX9-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX9-NEXT:    v_bfe_i32 v1, v1, 0, 8
-; GFX9-NEXT:    v_bfe_i32 v0, v0, 0, 8
-; GFX9-NEXT:    v_mul_hi_i32_i24_e32 v4, v0, v1
-; GFX9-NEXT:    v_mul_i32_i24_e32 v0, v0, v1
-; GFX9-NEXT:    v_bfe_i32 v1, v3, 0, 8
-; GFX9-NEXT:    v_bfe_i32 v2, v2, 0, 8
-; GFX9-NEXT:    v_mul_hi_i32_i24_e32 v3, v2, v1
-; GFX9-NEXT:    v_mul_i32_i24_e32 v1, v2, v1
-; GFX9-NEXT:    v_mul_lo_u32 v2, v4, v1
-; GFX9-NEXT:    v_mul_lo_u32 v3, v0, v3
-; GFX9-NEXT:    v_mul_hi_u32 v4, v0, v1
-; GFX9-NEXT:    v_mul_lo_u32 v0, v0, v1
-; GFX9-NEXT:    v_add3_u32 v1, v4, v3, v2
+; GFX9-NEXT:    v_mul_i32_i24_sdwa v0, sext(v0), sext(v1) dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:BYTE_0 src1_sel:BYTE_0
+; GFX9-NEXT:    v_mul_i32_i24_sdwa v2, sext(v2), sext(v3) dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:BYTE_0 src1_sel:BYTE_0
+; GFX9-NEXT:    v_mul_hi_i32_i24_e32 v1, v0, v2
+; GFX9-NEXT:    v_mul_i32_i24_e32 v0, v0, v2
 ; GFX9-NEXT:    v_lshrrev_b64 v[0:1], 24, v[0:1]
 ; GFX9-NEXT:    s_setpc_b64 s[30:31]
   %A = sext i8 %X to i48




More information about the llvm-commits mailing list