[PATCH] D118461: [AMDGPU] Introduce new ISel combine for trunc-slr patterns

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 2 07:24:00 PST 2022


foad added a comment.

> The XOR in the second test case (uniform) is there to prevent the truncate in the SDag from being optimized away and has no semantic relevance for the actual test.

OK, sorry, I did not read the test carefully enough. I have looked at it more carefully now.

So the problem is that this DAG:

      t4: i32 = and t2, Constant:i32<2>
    t7: i1 = setcc t4, Constant:i32<0>, setne:ch
  t9: i1,i64,ch = llvm.amdgcn.if t0, TargetConstant:i64<1324>, t7

gets optimized like this by a generic combine implemented in TargetLowering::SimplifySetCC:

      t24: i32 = srl t2, Constant:i64<1>
    t25: i1 = truncate t24
  t9: i1,i64,ch = llvm.amdgcn.if t0, TargetConstant:i64<1324>, t25

I guess there is no way we can undo that with another combine, because they will end up fighting each other. So I think your patch is reasonable.



================
Comment at: llvm/lib/Target/AMDGPU/SIInstructions.td:2290
+// v_and_b32_e64 $a, (1 << $b), $a
+// v_cmp_eq_u32_e64 $a, (1 << $b), $a 
+
----------------
foad wrote:
> `v_cmp_ne_u32_e64 $a, 0, $a` is probably better because 0 is always an inline constant, but `1 << $b` might not be.
Also, if you do this, there will only be one use of the constant not two, so I don't think you will have to "Restrict the range to prevent using an additional VGPR for the shifted value".


================
Comment at: llvm/test/CodeGen/AMDGPU/dagcombine-lshr-and-cmp.ll:1
+; RUN: llc -march=amdgcn -mtriple=amdgcn-- -stop-after=amdgpu-isel -verify-machineinstrs -O0 < %s | FileCheck -check-prefix=GCN %s
+
----------------
foad wrote:
> Please auto-generate the checks with utils/update_llc_test_checks.py and pre-commit this test with the old codegen, so that this patch will clearly show how the codegen changes.
Actually it will have to use update_mir_test_checks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118461/new/

https://reviews.llvm.org/D118461



More information about the llvm-commits mailing list