Skip to content

Commit

Permalink
[ARC] Improve code generated for i32 ADDC/ADDE and SUBC/SUBE
Browse files Browse the repository at this point in the history
This change improves the code generated for long long addition and subtraction

Differential Revision: https://reviews.llvm.org/D109615
  • Loading branch information
markschimmel committed Sep 10, 2021
1 parent eee7d22 commit 7c82db3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Target/ARC/ARCISelLowering.cpp
Expand Up @@ -121,6 +121,11 @@ ARCTargetLowering::ARCTargetLowering(const TargetMachine &TM,
setOperationAction(ISD::SMAX, MVT::i32, Legal);
setOperationAction(ISD::SMIN, MVT::i32, Legal);

setOperationAction(ISD::ADDC, MVT::i32, Legal);
setOperationAction(ISD::ADDE, MVT::i32, Legal);
setOperationAction(ISD::SUBC, MVT::i32, Legal);
setOperationAction(ISD::SUBE, MVT::i32, Legal);

// Need barrel shifter.
setOperationAction(ISD::SHL, MVT::i32, Legal);
setOperationAction(ISD::SRA, MVT::i32, Legal);
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Target/ARC/ARCInstrInfo.td
Expand Up @@ -328,6 +328,11 @@ defm : MultiPat<mul, MPY_rrr, MPY_rru6, MPY_rrlimm>;
defm : MultiPat<mulhs, MPYM_rrr, MPYM_rru6, MPYM_rrlimm>;
defm : MultiPat<mulhu, MPYMU_rrr, MPYMU_rru6, MPYMU_rrlimm>;

defm : MultiPat<addc, ADD_f_rrr, ADD_f_rru6, ADD_f_rrlimm>;
defm : MultiPat<adde, ADC_f_rrr, ADC_f_rru6, ADC_f_rrlimm>;
defm : MultiPat<subc, SUB_f_rrr, SUB_f_rru6, SUB_f_rrlimm>;
defm : MultiPat<sube, SBC_f_rrr, SBC_f_rru6, SBC_f_rrlimm>;

// ---------------------------------------------------------------------------
// Unary Instruction definitions.
// ---------------------------------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions llvm/test/CodeGen/ARC/alu.ll
Expand Up @@ -253,3 +253,20 @@ define i64 @muls64(i32 %a, i32 %b) nounwind {
ret i64 %v
}

; CHECK-LABEL: long_long_add
; CHECK: add.f %r0, %r0, %r2
; CHECK-NEXT: adc.f %r1, %r1, %r3
define i64 @long_long_add(i64 inreg %a, i64 inreg %b) #0 {
entry:
%add = add nsw i64 %a, %b
ret i64 %add
}

; CHECK-LABEL: long_long_sub
; CHECK: sub.f %r0, %r0, %r2
; CHECK-NEXT: sbc.f %r1, %r1, %r3
define i64 @long_long_sub(i64 inreg %a, i64 inreg %b) #0 {
entry:
%sub = sub nsw i64 %a, %b
ret i64 %sub
}

0 comments on commit 7c82db3

Please sign in to comment.