Skip to content

Commit

Permalink
[CSKY] Optimize conditional select with CLRT/CLRF
Browse files Browse the repository at this point in the history
Reviewed By: zixuan-wu

Differential Revision: https://reviews.llvm.org/D154409
  • Loading branch information
benshi001 committed Jul 4, 2023
1 parent ef53ec9 commit 3e6b80b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Target/CSKY/CSKYInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,11 @@ defm : MOVTF32Pat1<setuge, setule, CMPHS32, MOVT32>;
defm : MOVTF32Pat1<setult, setugt, CMPHS32, MOVF32>;
defm : MOVTF32Pat1<setlt, setgt, CMPLT32, MOVT32>;
defm : MOVTF32Pat1<setge, setle, CMPLT32, MOVF32>;

def : Pat<(select CARRY:$ca, (i32 0), GPR:$other),
(CLRT32 CARRY:$ca, GPR:$other)>;
def : Pat<(select CARRY:$ca, GPR:$other, (i32 0)),
(CLRF32 CARRY:$ca, GPR:$other)>;
}

// Constant materialize patterns.
Expand Down
8 changes: 3 additions & 5 deletions llvm/test/CodeGen/CSKY/select.ll
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ entry:
define i32 @selectRI_0_if_true(i1 %c, i32 %q) {
; CHECK-LABEL: selectRI_0_if_true:
; CHECK: # %bb.0:
; CHECK-NEXT: movi16 a2, 0
; CHECK-NEXT: btsti16 a0, 0
; CHECK-NEXT: movt32 a1, a2
; CHECK-NEXT: clrt32 a1
; CHECK-NEXT: mov16 a0, a1
; CHECK-NEXT: rts16
;
Expand All @@ -162,10 +161,9 @@ define i32 @selectRI_0_if_true(i1 %c, i32 %q) {
define i32 @selectRI_0_if_false(i1 %c, i32 %q) {
; CHECK-LABEL: selectRI_0_if_false:
; CHECK: # %bb.0:
; CHECK-NEXT: movi16 a2, 0
; CHECK-NEXT: btsti16 a0, 0
; CHECK-NEXT: movt32 a2, a1
; CHECK-NEXT: mov16 a0, a2
; CHECK-NEXT: clrf32 a1
; CHECK-NEXT: mov16 a0, a1
; CHECK-NEXT: rts16
;
; GENERIC-LABEL: selectRI_0_if_false:
Expand Down

0 comments on commit 3e6b80b

Please sign in to comment.