Skip to content

Commit

Permalink
[RISCV] Fix XTheadba patterns broken since cfc574a.
Browse files Browse the repository at this point in the history
Adding an OperandTransform to CSImm12MulBy4 and CSImm12MulBy8 for
Zba broke these patterns. They should have been changed in the same,
but we lacked sufficient testing.
  • Loading branch information
topperc committed Dec 27, 2024
1 parent cd3c165 commit 814902a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,9 @@ def : Pat<(add_non_imm12 sh3add_op:$rs1, (XLenVT GPR:$rs2)),
(TH_ADDSL GPR:$rs2, sh3add_op:$rs1, 3)>;

def : Pat<(add (XLenVT GPR:$r), CSImm12MulBy4:$i),
(TH_ADDSL GPR:$r, (XLenVT (ADDI (XLenVT X0), (SimmShiftRightBy2XForm CSImm12MulBy4:$i))), 2)>;
(TH_ADDSL GPR:$r, (XLenVT (ADDI (XLenVT X0), CSImm12MulBy4:$i)), 2)>;
def : Pat<(add (XLenVT GPR:$r), CSImm12MulBy8:$i),
(TH_ADDSL GPR:$r, (XLenVT (ADDI (XLenVT X0), (SimmShiftRightBy3XForm CSImm12MulBy8:$i))), 3)>;
(TH_ADDSL GPR:$r, (XLenVT (ADDI (XLenVT X0), CSImm12MulBy8:$i)), 3)>;

def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 200)),
(SLLI (XLenVT (TH_ADDSL (XLenVT (TH_ADDSL GPR:$r, GPR:$r, 2)),
Expand Down
36 changes: 24 additions & 12 deletions llvm/test/CodeGen/RISCV/rv32xtheadba.ll
Original file line number Diff line number Diff line change
Expand Up @@ -601,23 +601,35 @@ define i32 @mul4104(i32 %a) {
}

define i32 @add4104(i32 %a) {
; CHECK-LABEL: add4104:
; CHECK: # %bb.0:
; CHECK-NEXT: lui a1, 1
; CHECK-NEXT: addi a1, a1, 8
; CHECK-NEXT: add a0, a0, a1
; CHECK-NEXT: ret
; RV32I-LABEL: add4104:
; RV32I: # %bb.0:
; RV32I-NEXT: lui a1, 1
; RV32I-NEXT: addi a1, a1, 8
; RV32I-NEXT: add a0, a0, a1
; RV32I-NEXT: ret
;
; RV32XTHEADBA-LABEL: add4104:
; RV32XTHEADBA: # %bb.0:
; RV32XTHEADBA-NEXT: li a1, 1026
; RV32XTHEADBA-NEXT: th.addsl a0, a0, a1, 2
; RV32XTHEADBA-NEXT: ret
%c = add i32 %a, 4104
ret i32 %c
}

define i32 @add8208(i32 %a) {
; CHECK-LABEL: add8208:
; CHECK: # %bb.0:
; CHECK-NEXT: lui a1, 2
; CHECK-NEXT: addi a1, a1, 16
; CHECK-NEXT: add a0, a0, a1
; CHECK-NEXT: ret
; RV32I-LABEL: add8208:
; RV32I: # %bb.0:
; RV32I-NEXT: lui a1, 2
; RV32I-NEXT: addi a1, a1, 16
; RV32I-NEXT: add a0, a0, a1
; RV32I-NEXT: ret
;
; RV32XTHEADBA-LABEL: add8208:
; RV32XTHEADBA: # %bb.0:
; RV32XTHEADBA-NEXT: li a1, 1026
; RV32XTHEADBA-NEXT: th.addsl a0, a0, a1, 3
; RV32XTHEADBA-NEXT: ret
%c = add i32 %a, 8208
ret i32 %c
}
Expand Down
36 changes: 24 additions & 12 deletions llvm/test/CodeGen/RISCV/rv64xtheadba.ll
Original file line number Diff line number Diff line change
Expand Up @@ -966,12 +966,18 @@ define signext i32 @mulw576(i32 signext %a) {
}

define i64 @add4104(i64 %a) {
; CHECK-LABEL: add4104:
; CHECK: # %bb.0:
; CHECK-NEXT: lui a1, 1
; CHECK-NEXT: addiw a1, a1, 8
; CHECK-NEXT: add a0, a0, a1
; CHECK-NEXT: ret
; RV64I-LABEL: add4104:
; RV64I: # %bb.0:
; RV64I-NEXT: lui a1, 1
; RV64I-NEXT: addiw a1, a1, 8
; RV64I-NEXT: add a0, a0, a1
; RV64I-NEXT: ret
;
; RV64XTHEADBA-LABEL: add4104:
; RV64XTHEADBA: # %bb.0:
; RV64XTHEADBA-NEXT: li a1, 1026
; RV64XTHEADBA-NEXT: th.addsl a0, a0, a1, 2
; RV64XTHEADBA-NEXT: ret
%c = add i64 %a, 4104
ret i64 %c
}
Expand All @@ -988,12 +994,18 @@ define i64 @add4104_2(i64 %a) {
}

define i64 @add8208(i64 %a) {
; CHECK-LABEL: add8208:
; CHECK: # %bb.0:
; CHECK-NEXT: lui a1, 2
; CHECK-NEXT: addiw a1, a1, 16
; CHECK-NEXT: add a0, a0, a1
; CHECK-NEXT: ret
; RV64I-LABEL: add8208:
; RV64I: # %bb.0:
; RV64I-NEXT: lui a1, 2
; RV64I-NEXT: addiw a1, a1, 16
; RV64I-NEXT: add a0, a0, a1
; RV64I-NEXT: ret
;
; RV64XTHEADBA-LABEL: add8208:
; RV64XTHEADBA: # %bb.0:
; RV64XTHEADBA-NEXT: li a1, 1026
; RV64XTHEADBA-NEXT: th.addsl a0, a0, a1, 3
; RV64XTHEADBA-NEXT: ret
%c = add i64 %a, 8208
ret i64 %c
}
Expand Down

0 comments on commit 814902a

Please sign in to comment.