Skip to content

Commit 22fb21a

Browse files
authored
[DAG][ARM] canCreateUndefOrPoisonForTargetNode - ARMISD VORRIMM\VBICIMM nodes can't create poison/undef (#156831)
### Summary This PR resolves #156640
1 parent 316107f commit 22fb21a

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21363,6 +21363,19 @@ bool ARMTargetLowering::canCombineStoreAndExtract(Type *VectorTy, Value *Idx,
2136321363
return false;
2136421364
}
2136521365

21366+
bool ARMTargetLowering::canCreateUndefOrPoisonForTargetNode(
21367+
SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG,
21368+
bool PoisonOnly, bool ConsiderFlags, unsigned Depth) const {
21369+
unsigned Opcode = Op.getOpcode();
21370+
switch (Opcode) {
21371+
case ARMISD::VORRIMM:
21372+
case ARMISD::VBICIMM:
21373+
return false;
21374+
}
21375+
return TargetLowering::canCreateUndefOrPoisonForTargetNode(
21376+
Op, DemandedElts, DAG, PoisonOnly, ConsiderFlags, Depth);
21377+
}
21378+
2136621379
bool ARMTargetLowering::isCheapToSpeculateCttz(Type *Ty) const {
2136721380
return Subtarget->hasV5TOps() && !Subtarget->isThumb1Only();
2136821381
}

llvm/lib/Target/ARM/ARMISelLowering.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,10 @@ class VectorType;
707707
bool canCombineStoreAndExtract(Type *VectorTy, Value *Idx,
708708
unsigned &Cost) const override;
709709

710+
bool canCreateUndefOrPoisonForTargetNode(
711+
SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG,
712+
bool PoisonOnly, bool ConsiderFlags, unsigned Depth) const override;
713+
710714
bool canMergeStoresTo(unsigned AddressSpace, EVT MemVT,
711715
const MachineFunction &MF) const override {
712716
// Do not merge to larger than i32.

llvm/unittests/Target/ARM/ARMSelectionDAGTest.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ TEST_F(ARMSelectionDAGTest, computeKnownBits_VORRIMM) {
106106
KnownBits Known = DAG->computeKnownBits(Op, DemandedElts);
107107
EXPECT_EQ(Known.One, APInt(32, 0xAA));
108108
EXPECT_EQ(Known.Zero, APInt(32, 0x0));
109+
110+
// LHS(per-lane) = 00000000 00000000 00000000 00000000 (0x00000000)
111+
// Encoded(per-lane) = 00000000 00000000 00000000 10101010 (0x000000AA)
112+
// =>
113+
// Known.One = 00000000 00000000 00000000 10101010 (0x000000AA)
114+
// Known.Zero = 11111111 11111111 11111111 01010101 (0x00000000)
115+
SDValue Zero = DAG->getConstant(0, DL, MVT::i32);
116+
SDValue ZeroVec = DAG->getSplatBuildVector(VT, DL, Zero);
117+
Op = DAG->getNode(ARMISD::VORRIMM, DL, VT, ZeroVec, EncSD);
118+
SDValue FrVORRIMM = DAG->getFreeze(Op);
119+
Known = DAG->computeKnownBits(FrVORRIMM);
120+
EXPECT_EQ(Known.One, APInt(32, 0xAA));
121+
EXPECT_EQ(Known.Zero, APInt(32, 0xFFFFFF55));
109122
}
110123

111124
/// VBIC (immediate): x & ~imm with 32-bit elements.
@@ -129,6 +142,11 @@ TEST_F(ARMSelectionDAGTest, computeKnownBits_VBICIMM) {
129142
KnownBits Known = DAG->computeKnownBits(Op, DemandedElts);
130143
EXPECT_EQ(Known.One, APInt(32, 0xFFFFFF55));
131144
EXPECT_EQ(Known.Zero, APInt(32, 0x000000AA));
145+
146+
SDValue FrVBICIMM = DAG->getFreeze(Op);
147+
Known = DAG->computeKnownBits(FrVBICIMM);
148+
EXPECT_EQ(Known.One, APInt(32, 0xFFFFFF55));
149+
EXPECT_EQ(Known.Zero, APInt(32, 0x000000AA));
132150
}
133151

134152
/// VORR (immediate): per-lane OR with 32-bit elements.

0 commit comments

Comments
 (0)