[llvm] [DAG] Constant Folding for U/SMUL_LOHI (PR #69437)

Pierre van Houtryve via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 18 23:34:23 PDT 2023


================
@@ -2619,37 +2619,38 @@ define i64 @v_test_udiv64_mulhi_fold(i64 %arg) {
 ; VI-LABEL: v_test_udiv64_mulhi_fold:
 ; VI:       ; %bb.0:
 ; VI-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; VI-NEXT:    v_mov_b32_e32 v4, 0xa7c5
-; VI-NEXT:    v_mul_u32_u24_e32 v3, 0x500, v4
-; VI-NEXT:    v_mul_hi_u32_u24_e32 v2, 0x500, v4
-; VI-NEXT:    v_add_u32_e32 v3, vcc, 0x4237, v3
-; VI-NEXT:    v_addc_u32_e32 v5, vcc, 0, v2, vcc
-; VI-NEXT:    v_add_u32_e32 v6, vcc, 0xa9000000, v3
-; VI-NEXT:    s_mov_b32 s6, 0xfffe7960
-; VI-NEXT:    v_mad_u64_u32 v[2:3], s[4:5], v6, s6, 0
-; VI-NEXT:    v_addc_u32_e32 v7, vcc, v5, v4, vcc
-; VI-NEXT:    v_mul_lo_u32 v4, v7, s6
+; VI-NEXT:    s_mov_b32 s4, 0x346d900
+; VI-NEXT:    s_add_u32 s4, 0x4237, s4
----------------
Pierre-vh wrote:

We already have a `ConstantFoldBITCASTofBUILD_VECTOR` fold but it only runs before LegalizeTypes/Ops. Some targets need the bitcasts apparently. I tried doing it more often but only in specific cases (<=64 bit ints) but I still get infinite loops everywhere.

I think we need to add some helper to get splat values instead of checking ConstantSDNode when constant folding add. What do you think?

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


More information about the llvm-commits mailing list