[llvm] [LoongArch] Add patterns for `[x]vclo.{b/h/w/d}` instructions (PR #165985)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 1 02:53:45 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-loongarch
Author: ZhaoQi (zhaoqi5)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/165985.diff
4 Files Affected:
- (modified) llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td (+6)
- (modified) llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td (+6)
- (modified) llvm/test/CodeGen/LoongArch/lasx/ctpop-ctlz.ll (+4-11)
- (modified) llvm/test/CodeGen/LoongArch/lsx/ctpop-ctlz.ll (+4-11)
``````````diff
diff --git a/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td
index 610ba052fbdd5..6984a1c176ca0 100644
--- a/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td
+++ b/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td
@@ -1443,6 +1443,12 @@ defm : PatXrXr<sra, "XVSRA">;
defm : PatShiftXrXr<sra, "XVSRA">;
defm : PatShiftXrSplatUimm<sra, "XVSRAI">;
+// XVCLO_{B/H/W/D}
+def : Pat<(ctlz (vnot v32i8:$xj)), (XVCLO_B v32i8:$xj)>;
+def : Pat<(ctlz (vnot v16i16:$xj)), (XVCLO_H v16i16:$xj)>;
+def : Pat<(ctlz (vnot v8i32:$xj)), (XVCLO_W v8i32:$xj)>;
+def : Pat<(ctlz (vnot v4i64:$xj)), (XVCLO_D v4i64:$xj)>;
+
// XVCLZ_{B/H/W/D}
defm : PatXr<ctlz, "XVCLZ">;
diff --git a/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td
index 64708421c4ed4..a2edf3f2b6330 100644
--- a/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td
+++ b/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td
@@ -1645,6 +1645,12 @@ defm : PatVrVr<sra, "VSRA">;
defm : PatShiftVrVr<sra, "VSRA">;
defm : PatShiftVrSplatUimm<sra, "VSRAI">;
+// VCLO_{B/H/W/D}
+def : Pat<(ctlz (vnot v16i8:$vj)), (VCLO_B v16i8:$vj)>;
+def : Pat<(ctlz (vnot v8i16:$vj)), (VCLO_H v8i16:$vj)>;
+def : Pat<(ctlz (vnot v4i32:$vj)), (VCLO_W v4i32:$vj)>;
+def : Pat<(ctlz (vnot v2i64:$vj)), (VCLO_D v2i64:$vj)>;
+
// VCLZ_{B/H/W/D}
defm : PatVr<ctlz, "VCLZ">;
diff --git a/llvm/test/CodeGen/LoongArch/lasx/ctpop-ctlz.ll b/llvm/test/CodeGen/LoongArch/lasx/ctpop-ctlz.ll
index b3155c9313a8a..c8332170e80e1 100644
--- a/llvm/test/CodeGen/LoongArch/lasx/ctpop-ctlz.ll
+++ b/llvm/test/CodeGen/LoongArch/lasx/ctpop-ctlz.ll
@@ -110,8 +110,7 @@ define void @not_ctlz_v32i8(ptr %src, ptr %dst) nounwind {
; CHECK-LABEL: not_ctlz_v32i8:
; CHECK: # %bb.0:
; CHECK-NEXT: xvld $xr0, $a0, 0
-; CHECK-NEXT: xvxori.b $xr0, $xr0, 255
-; CHECK-NEXT: xvclz.b $xr0, $xr0
+; CHECK-NEXT: xvclo.b $xr0, $xr0
; CHECK-NEXT: xvst $xr0, $a1, 0
; CHECK-NEXT: ret
%v = load <32 x i8>, ptr %src
@@ -125,9 +124,7 @@ define void @not_ctlz_v16i16(ptr %src, ptr %dst) nounwind {
; CHECK-LABEL: not_ctlz_v16i16:
; CHECK: # %bb.0:
; CHECK-NEXT: xvld $xr0, $a0, 0
-; CHECK-NEXT: xvrepli.b $xr1, -1
-; CHECK-NEXT: xvxor.v $xr0, $xr0, $xr1
-; CHECK-NEXT: xvclz.h $xr0, $xr0
+; CHECK-NEXT: xvclo.h $xr0, $xr0
; CHECK-NEXT: xvst $xr0, $a1, 0
; CHECK-NEXT: ret
%v = load <16 x i16>, ptr %src
@@ -141,9 +138,7 @@ define void @not_ctlz_v8i32(ptr %src, ptr %dst) nounwind {
; CHECK-LABEL: not_ctlz_v8i32:
; CHECK: # %bb.0:
; CHECK-NEXT: xvld $xr0, $a0, 0
-; CHECK-NEXT: xvrepli.b $xr1, -1
-; CHECK-NEXT: xvxor.v $xr0, $xr0, $xr1
-; CHECK-NEXT: xvclz.w $xr0, $xr0
+; CHECK-NEXT: xvclo.w $xr0, $xr0
; CHECK-NEXT: xvst $xr0, $a1, 0
; CHECK-NEXT: ret
%v = load <8 x i32>, ptr %src
@@ -157,9 +152,7 @@ define void @not_ctlz_v4i64(ptr %src, ptr %dst) nounwind {
; CHECK-LABEL: not_ctlz_v4i64:
; CHECK: # %bb.0:
; CHECK-NEXT: xvld $xr0, $a0, 0
-; CHECK-NEXT: xvrepli.b $xr1, -1
-; CHECK-NEXT: xvxor.v $xr0, $xr0, $xr1
-; CHECK-NEXT: xvclz.d $xr0, $xr0
+; CHECK-NEXT: xvclo.d $xr0, $xr0
; CHECK-NEXT: xvst $xr0, $a1, 0
; CHECK-NEXT: ret
%v = load <4 x i64>, ptr %src
diff --git a/llvm/test/CodeGen/LoongArch/lsx/ctpop-ctlz.ll b/llvm/test/CodeGen/LoongArch/lsx/ctpop-ctlz.ll
index 6ac7d51de253b..dd577b4de9a7a 100644
--- a/llvm/test/CodeGen/LoongArch/lsx/ctpop-ctlz.ll
+++ b/llvm/test/CodeGen/LoongArch/lsx/ctpop-ctlz.ll
@@ -110,8 +110,7 @@ define void @not_ctlz_v16i8(ptr %src, ptr %dst) nounwind {
; CHECK-LABEL: not_ctlz_v16i8:
; CHECK: # %bb.0:
; CHECK-NEXT: vld $vr0, $a0, 0
-; CHECK-NEXT: vxori.b $vr0, $vr0, 255
-; CHECK-NEXT: vclz.b $vr0, $vr0
+; CHECK-NEXT: vclo.b $vr0, $vr0
; CHECK-NEXT: vst $vr0, $a1, 0
; CHECK-NEXT: ret
%v = load <16 x i8>, ptr %src
@@ -125,9 +124,7 @@ define void @not_ctlz_v8i16(ptr %src, ptr %dst) nounwind {
; CHECK-LABEL: not_ctlz_v8i16:
; CHECK: # %bb.0:
; CHECK-NEXT: vld $vr0, $a0, 0
-; CHECK-NEXT: vrepli.b $vr1, -1
-; CHECK-NEXT: vxor.v $vr0, $vr0, $vr1
-; CHECK-NEXT: vclz.h $vr0, $vr0
+; CHECK-NEXT: vclo.h $vr0, $vr0
; CHECK-NEXT: vst $vr0, $a1, 0
; CHECK-NEXT: ret
%v = load <8 x i16>, ptr %src
@@ -141,9 +138,7 @@ define void @not_ctlz_v4i32(ptr %src, ptr %dst) nounwind {
; CHECK-LABEL: not_ctlz_v4i32:
; CHECK: # %bb.0:
; CHECK-NEXT: vld $vr0, $a0, 0
-; CHECK-NEXT: vrepli.b $vr1, -1
-; CHECK-NEXT: vxor.v $vr0, $vr0, $vr1
-; CHECK-NEXT: vclz.w $vr0, $vr0
+; CHECK-NEXT: vclo.w $vr0, $vr0
; CHECK-NEXT: vst $vr0, $a1, 0
; CHECK-NEXT: ret
%v = load <4 x i32>, ptr %src
@@ -157,9 +152,7 @@ define void @not_ctlz_v2i64(ptr %src, ptr %dst) nounwind {
; CHECK-LABEL: not_ctlz_v2i64:
; CHECK: # %bb.0:
; CHECK-NEXT: vld $vr0, $a0, 0
-; CHECK-NEXT: vrepli.b $vr1, -1
-; CHECK-NEXT: vxor.v $vr0, $vr0, $vr1
-; CHECK-NEXT: vclz.d $vr0, $vr0
+; CHECK-NEXT: vclo.d $vr0, $vr0
; CHECK-NEXT: vst $vr0, $a1, 0
; CHECK-NEXT: ret
%v = load <2 x i64>, ptr %src
``````````
</details>
https://github.com/llvm/llvm-project/pull/165985
More information about the llvm-commits
mailing list