Skip to content

Commit 30e5845

Browse files
Fixed the issues with SDPatternMatch use.
1 parent 107d3d0 commit 30e5845

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#include <optional>
5252

5353
using namespace llvm;
54-
using namespace llvm::PatternMatch;
5554

5655
#define DEBUG_TYPE "riscv-lower"
5756

@@ -14318,35 +14317,36 @@ static SDValue transformAddShlImm(SDNode *N, SelectionDAG &DAG,
1431814317
// or 3.
1431914318
static bool checkAddiForShift(SDValue AddI, int64_t &AddConst,
1432014319
int64_t &ShlConst) {
14320+
using namespace llvm::SDPatternMatch;
1432114321
// Based on testing it seems that performance degrades if the ADDI has
1432214322
// more than 2 uses.
1432314323
if (AddI->use_size() > 2)
1432414324
return false;
1432514325

14326-
auto *AddConstNode = dyn_cast<ConstantSDNode>(AddI->getOperand(1));
14327-
if (!AddConstNode)
14326+
APInt AddVal;
14327+
SDValue SHLVal;
14328+
sd_match(AddI, m_Add(m_Value(SHLVal), m_ConstInt(AddVal)));
14329+
14330+
APInt VShift;
14331+
if (!sd_match(SHLVal, m_c_BinOp(ISD::SHL, m_Value(), m_ConstInt(VShift))))
1432814332
return false;
1432914333

14330-
SDValue SHLVal = AddI->getOperand(0);
14331-
if (SHLVal->getOpcode() != ISD::SHL)
14332-
return false;
14333-
14334-
auto *ShiftNode = dyn_cast<ConstantSDNode>(SHLVal->getOperand(1));
14335-
if (!ShiftNode)
14334+
if (VShift.slt(1) || VShift.sgt(3))
1433614335
return false;
1433714336

14338-
if (ShiftNode->getSExtValue() < 1 || ShiftNode->getSExtValue() > 3)
14339-
return false;
14340-
14341-
ShlConst = ShiftNode->getSExtValue();
14342-
AddConst = AddConstNode->getSExtValue();
14337+
// Set the values at the end when we know that the function will return
14338+
// true.
14339+
ShlConst = VShift.getSExtValue();
14340+
AddConst = AddVal.getSExtValue();
1434314341
return true;
1434414342
}
1434514343

1434614344
// Optimize (add (add (shl x, c0), c1), y) ->
1434714345
// (ADDI (SH*ADD y, x), c1), if c0 equals to [1|2|3].
1434814346
static SDValue combineShlAddIAdd(SDNode *N, SelectionDAG &DAG,
1434914347
const RISCVSubtarget &Subtarget) {
14348+
using namespace llvm::SDPatternMatch;
14349+
1435014350
// Perform this optimization only in the zba extension.
1435114351
if (!ReassocShlAddiAdd || !Subtarget.hasStdExtZba())
1435214352
return SDValue();
@@ -14362,12 +14362,8 @@ static SDValue combineShlAddIAdd(SDNode *N, SelectionDAG &DAG,
1436214362

1436314363
SDValue AddI = N->getOperand(0);
1436414364
SDValue Other = N->getOperand(1);
14365-
bool LHSIsAddI = SDPatternMatch::sd_match(
14366-
AddI, SDPatternMatch::m_Add(SDPatternMatch::m_Value(),
14367-
SDPatternMatch::m_ConstInt()));
14368-
bool RHSIsAddI = SDPatternMatch::sd_match(
14369-
Other, SDPatternMatch::m_Add(SDPatternMatch::m_Value(),
14370-
SDPatternMatch::m_ConstInt()));
14365+
bool LHSIsAddI = sd_match(AddI, m_Add(m_Value(), m_ConstInt()));
14366+
bool RHSIsAddI = sd_match(Other, m_Add(m_Value(), m_ConstInt()));
1437114367
int64_t AddConst = 0;
1437214368
int64_t ShlConst = 0;
1437314369

0 commit comments

Comments
 (0)