Skip to content

Commit ad80265

Browse files
authored
[RISCV] Qualify all XCV predicates with !is64Bit. (#101074)
The tablegen patterns all have isRV32. I did not check if any of them could naively support RV64. Fixes #101067 and probably other bugs like it we haven't found yet.
1 parent 5247959 commit ad80265

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
15401540
if (tryIndexedLoad(Node))
15411541
return;
15421542

1543-
if (Subtarget->hasVendorXCVmem()) {
1543+
if (Subtarget->hasVendorXCVmem() && !Subtarget->is64Bit()) {
15441544
// We match post-incrementing load here
15451545
LoadSDNode *Load = cast<LoadSDNode>(Node);
15461546
if (Load->getAddressingMode() != ISD::POST_INC)

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,14 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
250250
if (RV64LegalI32 && Subtarget.is64Bit())
251251
setOperationAction(ISD::SELECT_CC, MVT::i32, Expand);
252252

253-
if (!Subtarget.hasVendorXCValu())
254-
setCondCodeAction(ISD::SETLE, XLenVT, Expand);
255253
setCondCodeAction(ISD::SETGT, XLenVT, Custom);
256254
setCondCodeAction(ISD::SETGE, XLenVT, Expand);
257-
if (!Subtarget.hasVendorXCValu())
258-
setCondCodeAction(ISD::SETULE, XLenVT, Expand);
259255
setCondCodeAction(ISD::SETUGT, XLenVT, Custom);
260256
setCondCodeAction(ISD::SETUGE, XLenVT, Expand);
257+
if (!(Subtarget.hasVendorXCValu() && !Subtarget.is64Bit())) {
258+
setCondCodeAction(ISD::SETULE, XLenVT, Expand);
259+
setCondCodeAction(ISD::SETLE, XLenVT, Expand);
260+
}
261261

262262
if (RV64LegalI32 && Subtarget.is64Bit())
263263
setOperationAction(ISD::SETCC, MVT::i32, Promote);
@@ -343,7 +343,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
343343
if (Subtarget.is64Bit())
344344
setOperationAction({ISD::ROTL, ISD::ROTR}, MVT::i32, Custom);
345345
setOperationAction({ISD::ROTL, ISD::ROTR}, XLenVT, Custom);
346-
} else if (Subtarget.hasVendorXCVbitmanip()) {
346+
} else if (Subtarget.hasVendorXCVbitmanip() && !Subtarget.is64Bit()) {
347347
setOperationAction(ISD::ROTL, XLenVT, Expand);
348348
} else {
349349
setOperationAction({ISD::ROTL, ISD::ROTR}, XLenVT, Expand);
@@ -366,7 +366,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
366366
: Expand);
367367

368368

369-
if (Subtarget.hasVendorXCVbitmanip()) {
369+
if (Subtarget.hasVendorXCVbitmanip() && !Subtarget.is64Bit()) {
370370
setOperationAction(ISD::BITREVERSE, XLenVT, Legal);
371371
} else {
372372
// Zbkb can use rev8+brev8 to implement bitreverse.
@@ -387,14 +387,14 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
387387
else
388388
setOperationAction({ISD::CTTZ, ISD::CTTZ_ZERO_UNDEF}, MVT::i32, Custom);
389389
}
390-
} else if (!Subtarget.hasVendorXCVbitmanip()) {
390+
} else if (!(Subtarget.hasVendorXCVbitmanip() && !Subtarget.is64Bit())) {
391391
setOperationAction({ISD::CTTZ, ISD::CTPOP}, XLenVT, Expand);
392392
if (RV64LegalI32 && Subtarget.is64Bit())
393393
setOperationAction({ISD::CTTZ, ISD::CTPOP}, MVT::i32, Expand);
394394
}
395395

396396
if (Subtarget.hasStdExtZbb() || Subtarget.hasVendorXTHeadBb() ||
397-
Subtarget.hasVendorXCVbitmanip()) {
397+
(Subtarget.hasVendorXCVbitmanip() && !Subtarget.is64Bit())) {
398398
// We need the custom lowering to make sure that the resulting sequence
399399
// for the 32bit case is efficient on 64bit targets.
400400
if (Subtarget.is64Bit()) {
@@ -1439,7 +1439,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
14391439
}
14401440
}
14411441

1442-
if (Subtarget.hasVendorXCVmem()) {
1442+
if (Subtarget.hasVendorXCVmem() && !Subtarget.is64Bit()) {
14431443
setIndexedLoadAction(ISD::POST_INC, MVT::i8, Legal);
14441444
setIndexedLoadAction(ISD::POST_INC, MVT::i16, Legal);
14451445
setIndexedLoadAction(ISD::POST_INC, MVT::i32, Legal);
@@ -1449,7 +1449,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
14491449
setIndexedStoreAction(ISD::POST_INC, MVT::i32, Legal);
14501450
}
14511451

1452-
if (Subtarget.hasVendorXCValu()) {
1452+
if (Subtarget.hasVendorXCValu() && !Subtarget.is64Bit()) {
14531453
setOperationAction(ISD::ABS, XLenVT, Legal);
14541454
setOperationAction(ISD::SMIN, XLenVT, Legal);
14551455
setOperationAction(ISD::UMIN, XLenVT, Legal);
@@ -1928,12 +1928,13 @@ bool RISCVTargetLowering::signExtendConstant(const ConstantInt *CI) const {
19281928
}
19291929

19301930
bool RISCVTargetLowering::isCheapToSpeculateCttz(Type *Ty) const {
1931-
return Subtarget.hasStdExtZbb() || Subtarget.hasVendorXCVbitmanip();
1931+
return Subtarget.hasStdExtZbb() ||
1932+
(Subtarget.hasVendorXCVbitmanip() && !Subtarget.is64Bit());
19321933
}
19331934

19341935
bool RISCVTargetLowering::isCheapToSpeculateCtlz(Type *Ty) const {
19351936
return Subtarget.hasStdExtZbb() || Subtarget.hasVendorXTHeadBb() ||
1936-
Subtarget.hasVendorXCVbitmanip();
1937+
(Subtarget.hasVendorXCVbitmanip() && !Subtarget.is64Bit());
19371938
}
19381939

19391940
bool RISCVTargetLowering::isMaskAndCmp0FoldingBeneficial(
@@ -21088,7 +21089,7 @@ bool RISCVTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
2108821089
SDValue &Offset,
2108921090
ISD::MemIndexedMode &AM,
2109021091
SelectionDAG &DAG) const {
21091-
if (Subtarget.hasVendorXCVmem()) {
21092+
if (Subtarget.hasVendorXCVmem() && !Subtarget.is64Bit()) {
2109221093
if (Op->getOpcode() != ISD::ADD)
2109321094
return false;
2109421095

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ bool RISCVTTIImpl::hasActiveVectorLength(unsigned, Type *DataTy, Align) const {
280280
TargetTransformInfo::PopcntSupportKind
281281
RISCVTTIImpl::getPopcntSupport(unsigned TyWidth) {
282282
assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2");
283-
return ST->hasStdExtZbb() || ST->hasVendorXCVbitmanip()
283+
return ST->hasStdExtZbb() || (ST->hasVendorXCVbitmanip() && !ST->is64Bit())
284284
? TTI::PSK_FastHardware
285285
: TTI::PSK_Software;
286286
}

0 commit comments

Comments
 (0)