Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,8 @@ def : PatGpr<ctlz, CLZ_D>;
def : PatGpr<cttz, CTZ_D>;
def : Pat<(ctlz (not GPR:$rj)), (CLO_D GPR:$rj)>;
def : Pat<(cttz (not GPR:$rj)), (CTO_D GPR:$rj)>;
def : Pat<(cttz (or (not GPR:$rj), 256)), (CTO_D (ANDI GPR:$rj, 255))>;
def : Pat<(cttz (or (not GPR:$rj), 65536)), (CTO_D (BSTRPICK_D GPR:$rj, 15, 0))>;
def : PatGpr<loongarch_clzw, CLZ_W>;
def : PatGpr<loongarch_ctzw, CTZ_W>;
def : Pat<(loongarch_clzw (not GPR:$rj)), (CLO_W GPR:$rj)>;
Expand All @@ -1404,6 +1406,8 @@ def : PatGpr<ctlz, CLZ_W>;
def : PatGpr<cttz, CTZ_W>;
def : Pat<(ctlz (not GPR:$rj)), (CLO_W GPR:$rj)>;
def : Pat<(cttz (not GPR:$rj)), (CTO_W GPR:$rj)>;
def : Pat<(cttz (or (not GPR:$rj), 256)), (CTO_W (ANDI GPR:$rj, 255))>;
def : Pat<(cttz (or (not GPR:$rj), 65536)), (CTO_W (BSTRPICK_W GPR:$rj, 15, 0))>;
} // Predicates = [IsLA32, Has32S]

/// FrameIndex calculations
Expand Down
20 changes: 8 additions & 12 deletions llvm/test/CodeGen/LoongArch/ctlz-cttz-ctpop.ll
Original file line number Diff line number Diff line change
Expand Up @@ -901,16 +901,14 @@ define i8 @test_not_cttz_i8(i8 %a) nounwind {
;
; LA32S-LABEL: test_not_cttz_i8:
; LA32S: # %bb.0:
; LA32S-NEXT: ori $a1, $zero, 256
; LA32S-NEXT: orn $a0, $a1, $a0
; LA32S-NEXT: ctz.w $a0, $a0
; LA32S-NEXT: andi $a0, $a0, 255
; LA32S-NEXT: cto.w $a0, $a0
; LA32S-NEXT: ret
;
; LA64-LABEL: test_not_cttz_i8:
; LA64: # %bb.0:
; LA64-NEXT: ori $a1, $zero, 256
; LA64-NEXT: orn $a0, $a1, $a0
; LA64-NEXT: ctz.d $a0, $a0
; LA64-NEXT: andi $a0, $a0, 255
; LA64-NEXT: cto.d $a0, $a0
; LA64-NEXT: ret
%neg = xor i8 %a, -1
%tmp = call i8 @llvm.cttz.i8(i8 %neg, i1 false)
Expand Down Expand Up @@ -943,16 +941,14 @@ define i16 @test_not_cttz_i16(i16 %a) nounwind {
;
; LA32S-LABEL: test_not_cttz_i16:
; LA32S: # %bb.0:
; LA32S-NEXT: lu12i.w $a1, 16
; LA32S-NEXT: orn $a0, $a1, $a0
; LA32S-NEXT: ctz.w $a0, $a0
; LA32S-NEXT: bstrpick.w $a0, $a0, 15, 0
; LA32S-NEXT: cto.w $a0, $a0
; LA32S-NEXT: ret
;
; LA64-LABEL: test_not_cttz_i16:
; LA64: # %bb.0:
; LA64-NEXT: lu12i.w $a1, 16
; LA64-NEXT: orn $a0, $a1, $a0
; LA64-NEXT: ctz.d $a0, $a0
; LA64-NEXT: bstrpick.d $a0, $a0, 15, 0
; LA64-NEXT: cto.d $a0, $a0
; LA64-NEXT: ret
%neg = xor i16 %a, -1
%tmp = call i16 @llvm.cttz.i16(i16 %neg, i1 false)
Expand Down