Skip to content

Commit 1098a5c

Browse files
authored
[RISCV] Add commutative support for Qualcomm uC Xqcics extension (#161328)
This is a follow-up to #160653 doing similar changes for Xqcics.
1 parent 63ca848 commit 1098a5c

File tree

3 files changed

+136
-2
lines changed

3 files changed

+136
-2
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3793,6 +3793,11 @@ bool RISCVInstrInfo::findCommutedOpIndices(const MachineInstr &MI,
37933793
return false;
37943794
// Operands 1 and 2 are commutable, if we switch the opcode.
37953795
return fixCommutedOpIndices(SrcOpIdx1, SrcOpIdx2, 1, 2);
3796+
case RISCV::QC_SELECTIEQ:
3797+
case RISCV::QC_SELECTINE:
3798+
case RISCV::QC_SELECTIIEQ:
3799+
case RISCV::QC_SELECTIINE:
3800+
return fixCommutedOpIndices(SrcOpIdx1, SrcOpIdx2, 1, 2);
37963801
case RISCV::QC_MVEQ:
37973802
case RISCV::QC_MVNE:
37983803
case RISCV::QC_MVLT:
@@ -4018,6 +4023,11 @@ MachineInstr *RISCVInstrInfo::commuteInstructionImpl(MachineInstr &MI,
40184023
return TargetInstrInfo::commuteInstructionImpl(WorkingMI, false, OpIdx1,
40194024
OpIdx2);
40204025
}
4026+
case RISCV::QC_SELECTIEQ:
4027+
case RISCV::QC_SELECTINE:
4028+
case RISCV::QC_SELECTIIEQ:
4029+
case RISCV::QC_SELECTIINE:
4030+
return TargetInstrInfo::commuteInstructionImpl(MI, NewMI, OpIdx1, OpIdx2);
40214031
case RISCV::QC_MVEQ:
40224032
case RISCV::QC_MVNE:
40234033
case RISCV::QC_MVLT:

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ class QCIRVInstRI<bits<1> funct1, DAGOperand InTyImm11,
524524
let Inst{30-20} = imm11;
525525
}
526526

527-
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
527+
let hasSideEffects = 0, mayLoad = 0, mayStore = 0, isCommutable = 1 in
528528
class QCISELECTIICC<bits<3> funct3, string opcodestr>
529529
: RVInstR4<0b00, funct3, OPC_CUSTOM_2, (outs GPRNoX0:$rd_wb),
530530
(ins GPRNoX0:$rd, GPRNoX0:$rs1, simm5:$simm1, simm5:$simm2),
@@ -537,7 +537,7 @@ class QCISELECTIICC<bits<3> funct3, string opcodestr>
537537
let rs2 = simm1;
538538
}
539539

540-
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
540+
let hasSideEffects = 0, mayLoad = 0, mayStore = 0, isCommutable = 1 in
541541
class QCISELECTICC<bits<3> funct3, string opcodestr>
542542
: RVInstR4<0b01, funct3, OPC_CUSTOM_2, (outs GPRNoX0:$rd_wb),
543543
(ins GPRNoX0:$rd, GPRNoX0:$rs1, GPRNoX0:$rs2, simm5:$simm2),

llvm/test/CodeGen/RISCV/xqcics.ll

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,3 +690,127 @@ entry:
690690
ret i32 %sel
691691
}
692692

693+
define i32 @select_cc_example_eq1(i32 %a, i32 %b, i32 %x, i32 %y) {
694+
; RV32I-LABEL: select_cc_example_eq1:
695+
; RV32I: # %bb.0: # %entry
696+
; RV32I-NEXT: beq a1, a0, .LBB21_2
697+
; RV32I-NEXT: # %bb.1: # %entry
698+
; RV32I-NEXT: li a2, 11
699+
; RV32I-NEXT: .LBB21_2: # %entry
700+
; RV32I-NEXT: mv a0, a2
701+
; RV32I-NEXT: ret
702+
;
703+
; RV32IXQCICS-LABEL: select_cc_example_eq1:
704+
; RV32IXQCICS: # %bb.0: # %entry
705+
; RV32IXQCICS-NEXT: qc.selectieq a0, a1, a2, 11
706+
; RV32IXQCICS-NEXT: ret
707+
;
708+
; RV32IXQCICM-LABEL: select_cc_example_eq1:
709+
; RV32IXQCICM: # %bb.0: # %entry
710+
; RV32IXQCICM-NEXT: qc.selectieq a0, a1, a2, 11
711+
; RV32IXQCICM-NEXT: ret
712+
;
713+
; RV32IXQCI-LABEL: select_cc_example_eq1:
714+
; RV32IXQCI: # %bb.0: # %entry
715+
; RV32IXQCI-NEXT: qc.line a2, a1, a0, 11
716+
; RV32IXQCI-NEXT: mv a0, a2
717+
; RV32IXQCI-NEXT: ret
718+
entry:
719+
%cmp = icmp eq i32 %b, %a
720+
%sel = select i1 %cmp, i32 %x, i32 11
721+
ret i32 %sel
722+
}
723+
724+
define i32 @select_cc_example_ne1(i32 %a, i32 %b, i32 %x, i32 %y) {
725+
; RV32I-LABEL: select_cc_example_ne1:
726+
; RV32I: # %bb.0: # %entry
727+
; RV32I-NEXT: bne a1, a0, .LBB22_2
728+
; RV32I-NEXT: # %bb.1: # %entry
729+
; RV32I-NEXT: li a2, 11
730+
; RV32I-NEXT: .LBB22_2: # %entry
731+
; RV32I-NEXT: mv a0, a2
732+
; RV32I-NEXT: ret
733+
;
734+
; RV32IXQCICS-LABEL: select_cc_example_ne1:
735+
; RV32IXQCICS: # %bb.0: # %entry
736+
; RV32IXQCICS-NEXT: qc.selectine a0, a1, a2, 11
737+
; RV32IXQCICS-NEXT: ret
738+
;
739+
; RV32IXQCICM-LABEL: select_cc_example_ne1:
740+
; RV32IXQCICM: # %bb.0: # %entry
741+
; RV32IXQCICM-NEXT: qc.selectine a0, a1, a2, 11
742+
; RV32IXQCICM-NEXT: ret
743+
;
744+
; RV32IXQCI-LABEL: select_cc_example_ne1:
745+
; RV32IXQCI: # %bb.0: # %entry
746+
; RV32IXQCI-NEXT: qc.lieq a2, a1, a0, 11
747+
; RV32IXQCI-NEXT: mv a0, a2
748+
; RV32IXQCI-NEXT: ret
749+
entry:
750+
%cmp = icmp ne i32 %b, %a
751+
%sel = select i1 %cmp, i32 %x, i32 11
752+
ret i32 %sel
753+
}
754+
755+
756+
define i32 @select_cc_example_eq2(i32 %a, i32 %b, i32 %x, i32 %y) {
757+
; RV32I-LABEL: select_cc_example_eq2:
758+
; RV32I: # %bb.0: # %entry
759+
; RV32I-NEXT: beq a1, a0, .LBB23_2
760+
; RV32I-NEXT: # %bb.1: # %entry
761+
; RV32I-NEXT: li a0, 11
762+
; RV32I-NEXT: ret
763+
; RV32I-NEXT: .LBB23_2:
764+
; RV32I-NEXT: li a0, 15
765+
; RV32I-NEXT: ret
766+
;
767+
; RV32IXQCICS-LABEL: select_cc_example_eq2:
768+
; RV32IXQCICS: # %bb.0: # %entry
769+
; RV32IXQCICS-NEXT: qc.selectiieq a0, a1, 15, 11
770+
; RV32IXQCICS-NEXT: ret
771+
;
772+
; RV32IXQCICM-LABEL: select_cc_example_eq2:
773+
; RV32IXQCICM: # %bb.0: # %entry
774+
; RV32IXQCICM-NEXT: qc.selectiieq a0, a1, 15, 11
775+
; RV32IXQCICM-NEXT: ret
776+
;
777+
; RV32IXQCI-LABEL: select_cc_example_eq2:
778+
; RV32IXQCI: # %bb.0: # %entry
779+
; RV32IXQCI-NEXT: qc.selectiieq a0, a1, 15, 11
780+
; RV32IXQCI-NEXT: ret
781+
entry:
782+
%cmp = icmp eq i32 %b, %a
783+
%sel = select i1 %cmp, i32 15, i32 11
784+
ret i32 %sel
785+
}
786+
787+
define i32 @select_cc_example_ne2(i32 %a, i32 %b, i32 %x, i32 %y) {
788+
; RV32I-LABEL: select_cc_example_ne2:
789+
; RV32I: # %bb.0: # %entry
790+
; RV32I-NEXT: bne a1, a0, .LBB24_2
791+
; RV32I-NEXT: # %bb.1: # %entry
792+
; RV32I-NEXT: li a0, 11
793+
; RV32I-NEXT: ret
794+
; RV32I-NEXT: .LBB24_2:
795+
; RV32I-NEXT: li a0, 15
796+
; RV32I-NEXT: ret
797+
;
798+
; RV32IXQCICS-LABEL: select_cc_example_ne2:
799+
; RV32IXQCICS: # %bb.0: # %entry
800+
; RV32IXQCICS-NEXT: qc.selectiine a0, a1, 15, 11
801+
; RV32IXQCICS-NEXT: ret
802+
;
803+
; RV32IXQCICM-LABEL: select_cc_example_ne2:
804+
; RV32IXQCICM: # %bb.0: # %entry
805+
; RV32IXQCICM-NEXT: qc.selectiine a0, a1, 15, 11
806+
; RV32IXQCICM-NEXT: ret
807+
;
808+
; RV32IXQCI-LABEL: select_cc_example_ne2:
809+
; RV32IXQCI: # %bb.0: # %entry
810+
; RV32IXQCI-NEXT: qc.selectiine a0, a1, 15, 11
811+
; RV32IXQCI-NEXT: ret
812+
entry:
813+
%cmp = icmp ne i32 %b, %a
814+
%sel = select i1 %cmp, i32 15, i32 11
815+
ret i32 %sel
816+
}

0 commit comments

Comments
 (0)