Skip to content

Commit bacfdcd

Browse files
authored
[DAG] Add SDPatternMatch::m_BitCast matcher (#123327)
Simplifies a future patch
1 parent 8c63648 commit bacfdcd

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

llvm/include/llvm/CodeGen/SDPatternMatch.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,10 @@ inline UnaryOpc_match<Opnd, true> m_ChainedUnaryOp(unsigned Opc,
896896
return UnaryOpc_match<Opnd, true>(Opc, Op);
897897
}
898898

899+
template <typename Opnd> inline UnaryOpc_match<Opnd> m_BitCast(const Opnd &Op) {
900+
return UnaryOpc_match<Opnd>(ISD::BITCAST, Op);
901+
}
902+
899903
template <typename Opnd>
900904
inline UnaryOpc_match<Opnd> m_BSwap(const Opnd &Op) {
901905
return UnaryOpc_match<Opnd>(ISD::BSWAP, Op);

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15770,7 +15770,7 @@ SDValue DAGCombiner::foldBitcastedFPLogic(SDNode *N, SelectionDAG &DAG,
1577015770
// FIXME: I don't think looking for bitcast intrinsically makes sense, but
1577115771
// removing this would require more changes.
1577215772
auto IsBitCastOrFree = [&TLI, FPOpcode](SDValue Op, EVT VT) {
15773-
if (Op.getOpcode() == ISD::BITCAST && Op.getOperand(0).getValueType() == VT)
15773+
if (sd_match(Op, m_BitCast(m_SpecificVT(VT))))
1577415774
return true;
1577515775

1577615776
return FPOpcode == ISD::FABS ? TLI.isFAbsFree(VT) : TLI.isFNegFree(VT);

llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ TEST_F(SelectionDAGPatternMatchTest, matchUnaryOp) {
392392
SDValue FPToSI = DAG->getNode(ISD::FP_TO_SINT, DL, FloatVT, Op2);
393393
SDValue FPToUI = DAG->getNode(ISD::FP_TO_UINT, DL, FloatVT, Op2);
394394

395+
SDValue Bcast = DAG->getNode(ISD::BITCAST, DL, FloatVT, Op0);
395396
SDValue Brev = DAG->getNode(ISD::BITREVERSE, DL, Int32VT, Op0);
396397
SDValue Bswap = DAG->getNode(ISD::BSWAP, DL, Int32VT, Op0);
397398

@@ -423,8 +424,12 @@ TEST_F(SelectionDAGPatternMatchTest, matchUnaryOp) {
423424
EXPECT_FALSE(sd_match(FPToUI, m_FPToSI(m_Value())));
424425
EXPECT_FALSE(sd_match(FPToSI, m_FPToUI(m_Value())));
425426

427+
EXPECT_TRUE(sd_match(Bcast, m_BitCast(m_Value())));
428+
EXPECT_TRUE(sd_match(Bcast, m_BitCast(m_SpecificVT(MVT::i32))));
426429
EXPECT_TRUE(sd_match(Brev, m_BitReverse(m_Value())));
427430
EXPECT_TRUE(sd_match(Bswap, m_BSwap(m_Value())));
431+
EXPECT_FALSE(sd_match(Bcast, m_BitReverse(m_Value())));
432+
EXPECT_FALSE(sd_match(Bcast, m_BitCast(m_SpecificVT(MVT::f32))));
428433
EXPECT_FALSE(sd_match(Brev, m_BSwap(m_Value())));
429434
EXPECT_FALSE(sd_match(Bswap, m_BitReverse(m_Value())));
430435

0 commit comments

Comments
 (0)