Skip to content

Commit a960703

Browse files
authored
[RISCV] Remove incomplete PRE_DEC/POST_DEC code for XTHeadMemIdx. (#76922)
As far as I can tell if getIndexedAddressParts received an ISD::SUB, the constant would be negated. So `IsInc` should be set to true since the SUB was effectively converted to ADD. This means we should never use PRE_DEC/POST_DEC. No tests are affected because DAGCombine aggressively turns SUB with constant into ADD so no lit test has a SUB reach getIndexedAddressParts.
1 parent 4004f65 commit a960703

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -763,14 +763,12 @@ bool RISCVDAGToDAGISel::tryIndexedLoad(SDNode *Node) {
763763
return false;
764764

765765
EVT LoadVT = Ld->getMemoryVT();
766-
bool IsPre = (AM == ISD::PRE_INC || AM == ISD::PRE_DEC);
767-
bool IsPost = (AM == ISD::POST_INC || AM == ISD::POST_DEC);
766+
assert(AM == ISD::PRE_INC ||
767+
AM == ISD::POST_INC && "Unexpected addressing mode");
768+
bool IsPre = AM == ISD::PRE_INC;
769+
bool IsPost = AM == ISD::POST_INC;
768770
int64_t Offset = C->getSExtValue();
769771

770-
// Convert decrements to increments by a negative quantity.
771-
if (AM == ISD::PRE_DEC || AM == ISD::POST_DEC)
772-
Offset = -Offset;
773-
774772
// The constants that can be encoded in the THeadMemIdx instructions
775773
// are of the form (sign_extend(imm5) << imm2).
776774
int64_t Shift;

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,8 +1350,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
13501350
}
13511351

13521352
if (Subtarget.hasVendorXTHeadMemIdx()) {
1353-
for (unsigned im = (unsigned)ISD::PRE_INC; im != (unsigned)ISD::POST_DEC;
1354-
++im) {
1353+
for (unsigned im : {ISD::PRE_INC, ISD::POST_INC}) {
13551354
setIndexedLoadAction(im, MVT::i8, Legal);
13561355
setIndexedStoreAction(im, MVT::i8, Legal);
13571356
setIndexedLoadAction(im, MVT::i16, Legal);
@@ -19269,7 +19268,6 @@ bool RISCVTargetLowering::isVScaleKnownToBeAPowerOfTwo() const {
1926919268
bool RISCVTargetLowering::getIndexedAddressParts(SDNode *Op, SDValue &Base,
1927019269
SDValue &Offset,
1927119270
ISD::MemIndexedMode &AM,
19272-
bool &IsInc,
1927319271
SelectionDAG &DAG) const {
1927419272
// Target does not support indexed loads.
1927519273
if (!Subtarget.hasVendorXTHeadMemIdx())
@@ -19296,7 +19294,6 @@ bool RISCVTargetLowering::getIndexedAddressParts(SDNode *Op, SDValue &Base,
1929619294
if (!isLegalIndexedOffset)
1929719295
return false;
1929819296

19299-
IsInc = (Op->getOpcode() == ISD::ADD);
1930019297
Offset = Op->getOperand(1);
1930119298
return true;
1930219299
}
@@ -19319,11 +19316,10 @@ bool RISCVTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base,
1931919316
} else
1932019317
return false;
1932119318

19322-
bool IsInc;
19323-
if (!getIndexedAddressParts(Ptr.getNode(), Base, Offset, AM, IsInc, DAG))
19319+
if (!getIndexedAddressParts(Ptr.getNode(), Base, Offset, AM, DAG))
1932419320
return false;
1932519321

19326-
AM = IsInc ? ISD::PRE_INC : ISD::PRE_DEC;
19322+
AM = ISD::PRE_INC;
1932719323
return true;
1932819324
}
1932919325

@@ -19343,15 +19339,14 @@ bool RISCVTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
1934319339
} else
1934419340
return false;
1934519341

19346-
bool IsInc;
19347-
if (!getIndexedAddressParts(Op, Base, Offset, AM, IsInc, DAG))
19342+
if (!getIndexedAddressParts(Op, Base, Offset, AM, DAG))
1934819343
return false;
1934919344
// Post-indexing updates the base, so it's not a valid transform
1935019345
// if that's not the same as the load's pointer.
1935119346
if (Ptr != Base)
1935219347
return false;
1935319348

19354-
AM = IsInc ? ISD::POST_INC : ISD::POST_DEC;
19349+
AM = ISD::POST_INC;
1935519350
return true;
1935619351
}
1935719352

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,8 +774,7 @@ class RISCVTargetLowering : public TargetLowering {
774774
bool isVScaleKnownToBeAPowerOfTwo() const override;
775775

776776
bool getIndexedAddressParts(SDNode *Op, SDValue &Base, SDValue &Offset,
777-
ISD::MemIndexedMode &AM, bool &IsInc,
778-
SelectionDAG &DAG) const;
777+
ISD::MemIndexedMode &AM, SelectionDAG &DAG) const;
779778
bool getPreIndexedAddressParts(SDNode *N, SDValue &Base, SDValue &Offset,
780779
ISD::MemIndexedMode &AM,
781780
SelectionDAG &DAG) const override;

0 commit comments

Comments
 (0)