Skip to content

Commit e12be9c

Browse files
committed
[RISCV] Don't promote ISD::SELECT with rv64-legal-i32 when XTHeadCondMov is enabled.
Fixes an infinite loop. Test copied from the non-rv64-legal-i32 test.
1 parent dd0356d commit e12be9c

File tree

3 files changed

+2309
-4
lines changed

3 files changed

+2309
-4
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,11 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
411411
if (Subtarget.hasShortForwardBranchOpt())
412412
setOperationAction(ISD::ABS, XLenVT, Legal);
413413

414-
if (!Subtarget.hasVendorXTHeadCondMov())
414+
if (!Subtarget.hasVendorXTHeadCondMov()) {
415415
setOperationAction(ISD::SELECT, XLenVT, Custom);
416-
417-
if (RV64LegalI32 && Subtarget.is64Bit())
418-
setOperationAction(ISD::SELECT, MVT::i32, Promote);
416+
if (RV64LegalI32 && Subtarget.is64Bit())
417+
setOperationAction(ISD::SELECT, MVT::i32, Promote);
418+
}
419419

420420
static const unsigned FPLegalNodeTypes[] = {
421421
ISD::FMINNUM, ISD::FMAXNUM, ISD::LRINT,

llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,3 +909,24 @@ defm : StoreUpdatePat<post_truncsti16, TH_SHIA, i32>;
909909
defm : StoreUpdatePat<pre_truncsti16, TH_SHIB, i32>;
910910
}
911911

912+
let Predicates = [HasVendorXTHeadCondMov, IsRV64] in {
913+
def : Pat<(select (XLenVT GPR:$cond), (i32 GPR:$a), (i32 GPR:$b)),
914+
(TH_MVEQZ GPR:$a, GPR:$b, GPR:$cond)>;
915+
def : Pat<(select (XLenVT GPR:$cond), (i32 GPR:$a), (i32 0)),
916+
(TH_MVEQZ GPR:$a, (XLenVT X0), GPR:$cond)>;
917+
def : Pat<(select (XLenVT GPR:$cond), (i32 0), (i32 GPR:$b)),
918+
(TH_MVNEZ GPR:$b, (XLenVT X0), GPR:$cond)>;
919+
920+
def : Pat<(select (riscv_seteq (XLenVT GPR:$cond)), (i32 GPR:$a), (i32 GPR:$b)),
921+
(TH_MVNEZ GPR:$a, GPR:$b, GPR:$cond)>;
922+
def : Pat<(select (riscv_setne (XLenVT GPR:$cond)), (i32 GPR:$a), (i32 GPR:$b)),
923+
(TH_MVEQZ GPR:$a, GPR:$b, GPR:$cond)>;
924+
def : Pat<(select (riscv_seteq (XLenVT GPR:$cond)), (i32 GPR:$a), (i32 0)),
925+
(TH_MVNEZ GPR:$a, (XLenVT X0), GPR:$cond)>;
926+
def : Pat<(select (riscv_setne (XLenVT GPR:$cond)), (i32 GPR:$a), (i32 0)),
927+
(TH_MVEQZ GPR:$a, (XLenVT X0), GPR:$cond)>;
928+
def : Pat<(select (riscv_seteq (XLenVT GPR:$cond)), (i32 0), (i32 GPR:$b)),
929+
(TH_MVEQZ GPR:$b, (XLenVT X0), GPR:$cond)>;
930+
def : Pat<(select (riscv_setne (XLenVT GPR:$cond)), (i32 0), (i32 GPR:$b)),
931+
(TH_MVNEZ GPR:$b, (XLenVT X0), GPR:$cond)>;
932+
} // Predicates = [HasVendorXTHeadCondMov]

0 commit comments

Comments
 (0)