[PATCH] D66762: DAG: computeNumSignBits for MUL
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 26 11:11:34 PDT 2019
arsenm created this revision.
arsenm added reviewers: bogner, lebedev.ri, RKSimon, spatel, aaboud.
Herald added subscribers: nhaehnle, wdng, jvesely.
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.
https://reviews.llvm.org/D66762
Files:
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
test/CodeGen/AMDGPU/computeNumSignBits-mul.ll
Index: test/CodeGen/AMDGPU/computeNumSignBits-mul.ll
===================================================================
--- test/CodeGen/AMDGPU/computeNumSignBits-mul.ll
+++ test/CodeGen/AMDGPU/computeNumSignBits-mul.ll
@@ -7,7 +7,7 @@
; 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 @@
; 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
Index: lib/CodeGen/SelectionDAG/SelectionDAG.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -3715,6 +3715,20 @@
Tmp = ComputeNumSignBits(Op.getOperand(0), Depth+1);
if (Tmp == 1) return 1; // Early out.
return std::min(Tmp, Tmp2)-1;
+ case ISD::MUL: {
+ const unsigned TyBits = Op.getValueSizeInBits();
+
+ // 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 =
+ (TyBits - SignBitsOp0 + 1) + (TyBits - SignBitsOp1 + 1);
+ return OutValidBits > TyBits ? 1 : TyBits - 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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66762.217203.patch
Type: text/x-patch
Size: 2992 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190826/76fd27df/attachment.bin>
More information about the llvm-commits
mailing list