Skip to content

Commit db4d62a

Browse files
committed
[AArch64] canCreateUndefOrPoisonForTargetNode - AArch64ISD::VASHR can't create undef/poison
We can always fold freeze(vashr(x,y)) -> vashr(freeze(x),freeze(y)) as VASHR has defined behaviour for out-of-range shift amounts. Test coverage can be tricky, so I've hijacked a ComputeNumSignBits test to show that value tracking can still analyse the VASHR node as the FREEZE will have been discarded by the canCreateUndefOrPoison/isGuaranteedNotToBeUndefOrPoison logic in getFreeze(). If this AArch64SelectionDAGTest.cpp approach is OK I'm intending to use it in llvm#149323 once llvm#155696 has landed.
1 parent b96fa9f commit db4d62a

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30702,6 +30702,19 @@ bool AArch64TargetLowering::SimplifyDemandedBitsForTargetNode(
3070230702
Op, OriginalDemandedBits, OriginalDemandedElts, Known, TLO, Depth);
3070330703
}
3070430704

30705+
bool AArch64TargetLowering::canCreateUndefOrPoisonForTargetNode(
30706+
SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG,
30707+
bool PoisonOnly, bool ConsiderFlags, unsigned Depth) const {
30708+
30709+
// TODO: Add more target nodes.
30710+
switch (Op.getOpcode()) {
30711+
case AArch64ISD::VASHR:
30712+
return false;
30713+
}
30714+
return TargetLowering::canCreateUndefOrPoisonForTargetNode(
30715+
Op, DemandedElts, DAG, PoisonOnly, ConsiderFlags, Depth);
30716+
}
30717+
3070530718
bool AArch64TargetLowering::isTargetCanonicalConstantNode(SDValue Op) const {
3070630719
return Op.getOpcode() == AArch64ISD::DUP ||
3070730720
Op.getOpcode() == AArch64ISD::MOVI ||

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,12 @@ class AArch64TargetLowering : public TargetLowering {
868868
TargetLoweringOpt &TLO,
869869
unsigned Depth) const override;
870870

871+
bool canCreateUndefOrPoisonForTargetNode(SDValue Op,
872+
const APInt &DemandedElts,
873+
const SelectionDAG &DAG,
874+
bool PoisonOnly, bool ConsiderFlags,
875+
unsigned Depth) const override;
876+
871877
bool isTargetCanonicalConstantNode(SDValue Op) const override;
872878

873879
// With the exception of data-predicate transitions, no instructions are

llvm/test/CodeGen/AArch64/vector-compress.ll

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ define <4 x i32> @test_compress_v4i32(<4 x i32> %vec, <4 x i1> %mask) {
1212
; CHECK-NEXT: shl.4s v1, v1, #31
1313
; CHECK-NEXT: cmlt.4s v1, v1, #0
1414
; CHECK-NEXT: mov.s w9, v1[1]
15-
; CHECK-NEXT: mov.s w10, v1[2]
1615
; CHECK-NEXT: fmov w11, s1
16+
; CHECK-NEXT: mov.s w10, v1[2]
17+
; CHECK-NEXT: and x12, x11, #0x1
1718
; CHECK-NEXT: bfi x8, x11, #2, #1
18-
; CHECK-NEXT: and x11, x11, #0x1
19-
; CHECK-NEXT: and x9, x9, #0x1
20-
; CHECK-NEXT: and w10, w10, #0x1
21-
; CHECK-NEXT: add x9, x11, x9
2219
; CHECK-NEXT: mov x11, sp
20+
; CHECK-NEXT: and x9, x9, #0x1
21+
; CHECK-NEXT: add x9, x12, x9
2322
; CHECK-NEXT: st1.s { v0 }[1], [x8]
24-
; CHECK-NEXT: add w10, w9, w10
23+
; CHECK-NEXT: sub w10, w9, w10
2524
; CHECK-NEXT: orr x9, x11, x9, lsl #2
2625
; CHECK-NEXT: bfi x11, x10, #2, #2
2726
; CHECK-NEXT: st1.s { v0 }[2], [x9]
@@ -93,7 +92,8 @@ define <2 x double> @test_compress_v2f64(<2 x double> %vec, <2 x i1> %mask) {
9392
; CHECK-NEXT: shl.2d v1, v1, #63
9493
; CHECK-NEXT: cmlt.2d v1, v1, #0
9594
; CHECK-NEXT: fmov x9, d1
96-
; CHECK-NEXT: bfi x8, x9, #3, #1
95+
; CHECK-NEXT: and x9, x9, #0x8
96+
; CHECK-NEXT: orr x8, x8, x9
9797
; CHECK-NEXT: st1.d { v0 }[1], [x8]
9898
; CHECK-NEXT: ldr q0, [sp], #16
9999
; CHECK-NEXT: ret
@@ -420,16 +420,15 @@ define <3 x i32> @test_compress_narrow(<3 x i32> %vec, <3 x i1> %mask) {
420420
; CHECK-NEXT: shl.4s v1, v1, #31
421421
; CHECK-NEXT: cmlt.4s v1, v1, #0
422422
; CHECK-NEXT: mov.s w8, v1[1]
423-
; CHECK-NEXT: mov.s w9, v1[2]
424423
; CHECK-NEXT: fmov w10, s1
424+
; CHECK-NEXT: mov.s w9, v1[2]
425+
; CHECK-NEXT: and x12, x10, #0x1
425426
; CHECK-NEXT: bfi x11, x10, #2, #1
426-
; CHECK-NEXT: and x10, x10, #0x1
427-
; CHECK-NEXT: and x8, x8, #0x1
428-
; CHECK-NEXT: and w9, w9, #0x1
429-
; CHECK-NEXT: add x8, x10, x8
430427
; CHECK-NEXT: mov x10, sp
428+
; CHECK-NEXT: and x8, x8, #0x1
429+
; CHECK-NEXT: add x8, x12, x8
431430
; CHECK-NEXT: st1.s { v0 }[1], [x11]
432-
; CHECK-NEXT: add w9, w8, w9
431+
; CHECK-NEXT: sub w9, w8, w9
433432
; CHECK-NEXT: orr x8, x10, x8, lsl #2
434433
; CHECK-NEXT: bfi x10, x9, #2, #2
435434
; CHECK-NEXT: st1.s { v0 }[2], [x8]

llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ TEST_F(AArch64SelectionDAGTest, ComputeNumSignBits_VASHR) {
172172
auto VecA = DAG->getConstant(0xaa, Loc, VecVT);
173173
auto Op2 = DAG->getNode(AArch64ISD::VASHR, Loc, VecVT, VecA, Shift);
174174
EXPECT_EQ(DAG->ComputeNumSignBits(Op2), 5u);
175+
// VASHR can't create undef/poison - FREEZE(VASHR(C1,C2)) -> VASHR(C1,C2).
176+
auto Fr2 = DAG->getFreeze(Op2);
177+
EXPECT_EQ(DAG->ComputeNumSignBits(Fr2), 5u);
175178
}
176179

177180
TEST_F(AArch64SelectionDAGTest, SimplifyDemandedVectorElts_EXTRACT_SUBVECTOR) {

0 commit comments

Comments
 (0)