Skip to content

Commit 667fd20

Browse files
committed
Merge branch 'main' of https://github.com/llvm/llvm-project into private_is_an_evil_default
2 parents 2b2c236 + 49fa91e commit 667fd20

File tree

4 files changed

+167
-6
lines changed

4 files changed

+167
-6
lines changed

llvm/include/llvm/CodeGen/SDPatternMatch.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,16 @@ inline BinaryOpc_match<LHS, RHS> m_Srl(const LHS &L, const RHS &R) {
759759
return BinaryOpc_match<LHS, RHS>(ISD::SRL, L, R);
760760
}
761761

762+
template <typename LHS, typename RHS>
763+
inline BinaryOpc_match<LHS, RHS> m_Rotl(const LHS &L, const RHS &R) {
764+
return BinaryOpc_match<LHS, RHS>(ISD::ROTL, L, R);
765+
}
766+
767+
template <typename LHS, typename RHS>
768+
inline BinaryOpc_match<LHS, RHS> m_Rotr(const LHS &L, const RHS &R) {
769+
return BinaryOpc_match<LHS, RHS>(ISD::ROTR, L, R);
770+
}
771+
762772
template <typename LHS, typename RHS>
763773
inline BinaryOpc_match<LHS, RHS, true> m_FAdd(const LHS &L, const RHS &R) {
764774
return BinaryOpc_match<LHS, RHS, true>(ISD::FADD, L, R);
@@ -822,6 +832,11 @@ inline UnaryOpc_match<Opnd, true> m_ChainedUnaryOp(unsigned Opc,
822832
return UnaryOpc_match<Opnd, true>(Opc, Op);
823833
}
824834

835+
template <typename Opnd>
836+
inline UnaryOpc_match<Opnd> m_BSwap(const Opnd &Op) {
837+
return UnaryOpc_match<Opnd>(ISD::BSWAP, Op);
838+
}
839+
825840
template <typename Opnd>
826841
inline UnaryOpc_match<Opnd> m_BitReverse(const Opnd &Op) {
827842
return UnaryOpc_match<Opnd>(ISD::BITREVERSE, Op);
@@ -892,10 +907,18 @@ template <typename Opnd> inline UnaryOpc_match<Opnd> m_FPToSI(const Opnd &Op) {
892907
return UnaryOpc_match<Opnd>(ISD::FP_TO_SINT, Op);
893908
}
894909

910+
template <typename Opnd> inline UnaryOpc_match<Opnd> m_Ctpop(const Opnd &Op) {
911+
return UnaryOpc_match<Opnd>(ISD::CTPOP, Op);
912+
}
913+
895914
template <typename Opnd> inline UnaryOpc_match<Opnd> m_Ctlz(const Opnd &Op) {
896915
return UnaryOpc_match<Opnd>(ISD::CTLZ, Op);
897916
}
898917

918+
template <typename Opnd> inline UnaryOpc_match<Opnd> m_Cttz(const Opnd &Op) {
919+
return UnaryOpc_match<Opnd>(ISD::CTTZ, Op);
920+
}
921+
899922
// === Constants ===
900923
struct ConstantInt_match {
901924
APInt *BindVal;

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9594,6 +9594,7 @@ SDValue DAGCombiner::visitXOR(SDNode *N) {
95949594
}
95959595

95969596
// fold (not (or x, y)) -> (and (not x), (not y)) iff x or y are setcc
9597+
// fold (not (and x, y)) -> (or (not x), (not y)) iff x or y are setcc
95979598
if (isOneConstant(N1) && VT == MVT::i1 && N0.hasOneUse() &&
95989599
(N0Opcode == ISD::OR || N0Opcode == ISD::AND)) {
95999600
SDValue N00 = N0.getOperand(0), N01 = N0.getOperand(1);

llvm/test/CodeGen/X86/pr108731.ll

Lines changed: 121 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
; RUN: llc < %s -mtriple=x86_64-- -mcpu=x86-64-v2 | FileCheck %s --check-prefixes=CHECK,NOBMI
33
; RUN: llc < %s -mtriple=x86_64-- -mcpu=x86-64-v3 | FileCheck %s --check-prefixes=CHECK,BMI
44

5-
define i64 @foo(i64 %w, i64 %x, i64 %y, i64 %z) {
6-
; NOBMI-LABEL: foo:
5+
define i64 @test_i64(i64 %w, i64 %x, i64 %y, i64 %z) {
6+
; NOBMI-LABEL: test_i64:
77
; NOBMI: # %bb.0: # %Entry
88
; NOBMI-NEXT: movq %rcx, %rax
99
; NOBMI-NEXT: andq %rdx, %rsi
@@ -14,7 +14,7 @@ define i64 @foo(i64 %w, i64 %x, i64 %y, i64 %z) {
1414
; NOBMI-NEXT: andq %rsi, %rax
1515
; NOBMI-NEXT: retq
1616
;
17-
; BMI-LABEL: foo:
17+
; BMI-LABEL: test_i64:
1818
; BMI: # %bb.0: # %Entry
1919
; BMI-NEXT: andq %rdx, %rsi
2020
; BMI-NEXT: andnq %rdi, %rsi, %rax
@@ -31,8 +31,91 @@ Entry:
3131
ret i64 %and3
3232
}
3333

34-
define <16 x i8> @fooVec(<16 x i8> %w, <16 x i8> %x, <16 x i8> %y, <16 x i8> %z) {
35-
; NOBMI-LABEL: fooVec:
34+
define i32 @test_i32(i32 %w, i32 %x, i32 %y, i32 %z) {
35+
; NOBMI-LABEL: test_i32:
36+
; NOBMI: # %bb.0: # %Entry
37+
; NOBMI-NEXT: movl %ecx, %eax
38+
; NOBMI-NEXT: andl %edx, %esi
39+
; NOBMI-NEXT: notl %esi
40+
; NOBMI-NEXT: andl %edi, %esi
41+
; NOBMI-NEXT: notl %eax
42+
; NOBMI-NEXT: orl %edx, %eax
43+
; NOBMI-NEXT: andl %esi, %eax
44+
; NOBMI-NEXT: retq
45+
;
46+
; BMI-LABEL: test_i32:
47+
; BMI: # %bb.0: # %Entry
48+
; BMI-NEXT: andl %edx, %esi
49+
; BMI-NEXT: andnl %edi, %esi, %eax
50+
; BMI-NEXT: andnl %ecx, %edx, %ecx
51+
; BMI-NEXT: andnl %eax, %ecx, %eax
52+
; BMI-NEXT: retq
53+
Entry:
54+
%and1 = and i32 %y, %x
55+
%xor1 = xor i32 %and1, -1
56+
%and2 = and i32 %xor1, %w
57+
%.not = xor i32 %z, -1
58+
%or1 = or i32 %.not, %y
59+
%and3 = and i32 %and2, %or1
60+
ret i32 %and3
61+
}
62+
63+
define i16 @test_i16(i16 %w, i16 %x, i16 %y, i16 %z) {
64+
; NOBMI-LABEL: test_i16:
65+
; NOBMI: # %bb.0: # %Entry
66+
; NOBMI-NEXT: movl %ecx, %eax
67+
; NOBMI-NEXT: andl %edx, %esi
68+
; NOBMI-NEXT: notl %esi
69+
; NOBMI-NEXT: andl %edi, %esi
70+
; NOBMI-NEXT: notl %eax
71+
; NOBMI-NEXT: orl %edx, %eax
72+
; NOBMI-NEXT: andl %esi, %eax
73+
; NOBMI-NEXT: # kill: def $ax killed $ax killed $eax
74+
; NOBMI-NEXT: retq
75+
;
76+
; BMI-LABEL: test_i16:
77+
; BMI: # %bb.0: # %Entry
78+
; BMI-NEXT: andl %edx, %esi
79+
; BMI-NEXT: andnl %edi, %esi, %eax
80+
; BMI-NEXT: notl %ecx
81+
; BMI-NEXT: orl %edx, %ecx
82+
; BMI-NEXT: andl %ecx, %eax
83+
; BMI-NEXT: # kill: def $ax killed $ax killed $eax
84+
; BMI-NEXT: retq
85+
Entry:
86+
%and1 = and i16 %y, %x
87+
%xor1 = xor i16 %and1, -1
88+
%and2 = and i16 %xor1, %w
89+
%.not = xor i16 %z, -1
90+
%or1 = or i16 %.not, %y
91+
%and3 = and i16 %and2, %or1
92+
ret i16 %and3
93+
}
94+
95+
define i8 @test_i8(i8 %w, i8 %x, i8 %y, i8 %z) {
96+
; CHECK-LABEL: test_i8:
97+
; CHECK: # %bb.0: # %Entry
98+
; CHECK-NEXT: movl %edx, %eax
99+
; CHECK-NEXT: andl %edx, %esi
100+
; CHECK-NEXT: notb %sil
101+
; CHECK-NEXT: andb %dil, %sil
102+
; CHECK-NEXT: notb %cl
103+
; CHECK-NEXT: orb %cl, %al
104+
; CHECK-NEXT: andb %sil, %al
105+
; CHECK-NEXT: # kill: def $al killed $al killed $eax
106+
; CHECK-NEXT: retq
107+
Entry:
108+
%and1 = and i8 %y, %x
109+
%xor1 = xor i8 %and1, -1
110+
%and2 = and i8 %xor1, %w
111+
%.not = xor i8 %z, -1
112+
%or1 = or i8 %.not, %y
113+
%and3 = and i8 %and2, %or1
114+
ret i8 %and3
115+
}
116+
117+
define <16 x i8> @test_v16i8(<16 x i8> %w, <16 x i8> %x, <16 x i8> %y, <16 x i8> %z) {
118+
; NOBMI-LABEL: test_v16i8:
36119
; NOBMI: # %bb.0: # %Entry
37120
; NOBMI-NEXT: andps %xmm2, %xmm1
38121
; NOBMI-NEXT: andnps %xmm0, %xmm1
@@ -41,7 +124,7 @@ define <16 x i8> @fooVec(<16 x i8> %w, <16 x i8> %x, <16 x i8> %y, <16 x i8> %z)
41124
; NOBMI-NEXT: movaps %xmm2, %xmm0
42125
; NOBMI-NEXT: retq
43126
;
44-
; BMI-LABEL: fooVec:
127+
; BMI-LABEL: test_v16i8:
45128
; BMI: # %bb.0: # %Entry
46129
; BMI-NEXT: vandps %xmm1, %xmm2, %xmm1
47130
; BMI-NEXT: vandnps %xmm0, %xmm1, %xmm0
@@ -58,6 +141,38 @@ Entry:
58141
ret <16 x i8> %and3
59142
}
60143

144+
define <32 x i8> @test_v32i8(<32 x i8> %w, <32 x i8> %x, <32 x i8> %y, <32 x i8> %z) {
145+
; NOBMI-LABEL: test_v32i8:
146+
; NOBMI: # %bb.0: # %Entry
147+
; NOBMI-NEXT: andps %xmm4, %xmm2
148+
; NOBMI-NEXT: andps %xmm5, %xmm3
149+
; NOBMI-NEXT: andnps %xmm1, %xmm3
150+
; NOBMI-NEXT: andnps %xmm0, %xmm2
151+
; NOBMI-NEXT: andnps %xmm6, %xmm4
152+
; NOBMI-NEXT: andnps %xmm2, %xmm4
153+
; NOBMI-NEXT: andnps %xmm7, %xmm5
154+
; NOBMI-NEXT: andnps %xmm3, %xmm5
155+
; NOBMI-NEXT: movaps %xmm4, %xmm0
156+
; NOBMI-NEXT: movaps %xmm5, %xmm1
157+
; NOBMI-NEXT: retq
158+
;
159+
; BMI-LABEL: test_v32i8:
160+
; BMI: # %bb.0: # %Entry
161+
; BMI-NEXT: vandps %ymm1, %ymm2, %ymm1
162+
; BMI-NEXT: vandnps %ymm0, %ymm1, %ymm0
163+
; BMI-NEXT: vandnps %ymm3, %ymm2, %ymm1
164+
; BMI-NEXT: vandnps %ymm0, %ymm1, %ymm0
165+
; BMI-NEXT: retq
166+
Entry:
167+
%and1 = and <32 x i8> %y, %x
168+
%xor1 = xor <32 x i8> %and1, <i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1>
169+
%and2 = and <32 x i8> %xor1, %w
170+
%.not = xor <32 x i8> %z, <i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1>
171+
%or1 = or <32 x i8> %.not, %y
172+
%and3 = and <32 x i8> %and2, %or1
173+
ret <32 x i8> %and3
174+
}
175+
61176
; PR112347 - don't fold if we'd be inverting a constant, as demorgan normalisation will invert it back again.
62177
define void @PR112347(ptr %p0, ptr %p1, ptr %p2) {
63178
; CHECK-LABEL: PR112347:

llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ TEST_F(SelectionDAGPatternMatchTest, matchBinaryOp) {
200200
SDValue SMin = DAG->getNode(ISD::SMIN, DL, Int32VT, Op1, Op0);
201201
SDValue UMax = DAG->getNode(ISD::UMAX, DL, Int32VT, Op0, Op1);
202202
SDValue UMin = DAG->getNode(ISD::UMIN, DL, Int32VT, Op1, Op0);
203+
SDValue Rotl = DAG->getNode(ISD::ROTL, DL, Int32VT, Op0, Op1);
204+
SDValue Rotr = DAG->getNode(ISD::ROTR, DL, Int32VT, Op1, Op0);
203205

204206
SDValue ICMP_GT = DAG->getSetCC(DL, MVT::i1, Op0, Op1, ISD::SETGT);
205207
SDValue ICMP_GE = DAG->getSetCC(DL, MVT::i1, Op0, Op1, ISD::SETGE);
@@ -246,6 +248,11 @@ TEST_F(SelectionDAGPatternMatchTest, matchBinaryOp) {
246248
EXPECT_FALSE(sd_match(DisOr, m_Add(m_Value(), m_Value())));
247249
EXPECT_TRUE(sd_match(DisOr, m_AddLike(m_Value(), m_Value())));
248250

251+
EXPECT_TRUE(sd_match(Rotl, m_Rotl(m_Value(), m_Value())));
252+
EXPECT_TRUE(sd_match(Rotr, m_Rotr(m_Value(), m_Value())));
253+
EXPECT_FALSE(sd_match(Rotl, m_Rotr(m_Value(), m_Value())));
254+
EXPECT_FALSE(sd_match(Rotr, m_Rotl(m_Value(), m_Value())));
255+
249256
EXPECT_TRUE(sd_match(SMax, m_c_BinOp(ISD::SMAX, m_Value(), m_Value())));
250257
EXPECT_TRUE(sd_match(SMax, m_SMax(m_Value(), m_Value())));
251258
EXPECT_TRUE(sd_match(SMax, m_SMaxLike(m_Value(), m_Value())));
@@ -302,7 +309,12 @@ TEST_F(SelectionDAGPatternMatchTest, matchUnaryOp) {
302309
SDValue FPToSI = DAG->getNode(ISD::FP_TO_SINT, DL, FloatVT, Op2);
303310
SDValue FPToUI = DAG->getNode(ISD::FP_TO_UINT, DL, FloatVT, Op2);
304311

312+
SDValue Brev = DAG->getNode(ISD::BITREVERSE, DL, Int32VT, Op0);
313+
SDValue Bswap = DAG->getNode(ISD::BSWAP, DL, Int32VT, Op0);
314+
315+
SDValue Ctpop = DAG->getNode(ISD::CTPOP, DL, Int32VT, Op0);
305316
SDValue Ctlz = DAG->getNode(ISD::CTLZ, DL, Int32VT, Op0);
317+
SDValue Cttz = DAG->getNode(ISD::CTTZ, DL, Int32VT, Op0);
306318

307319
using namespace SDPatternMatch;
308320
EXPECT_TRUE(sd_match(ZExt, m_UnaryOp(ISD::ZERO_EXTEND, m_Value())));
@@ -328,7 +340,17 @@ TEST_F(SelectionDAGPatternMatchTest, matchUnaryOp) {
328340
EXPECT_FALSE(sd_match(FPToUI, m_FPToSI(m_Value())));
329341
EXPECT_FALSE(sd_match(FPToSI, m_FPToUI(m_Value())));
330342

343+
EXPECT_TRUE(sd_match(Brev, m_BitReverse(m_Value())));
344+
EXPECT_TRUE(sd_match(Bswap, m_BSwap(m_Value())));
345+
EXPECT_FALSE(sd_match(Brev, m_BSwap(m_Value())));
346+
EXPECT_FALSE(sd_match(Bswap, m_BitReverse(m_Value())));
347+
348+
EXPECT_TRUE(sd_match(Ctpop, m_Ctpop(m_Value())));
331349
EXPECT_TRUE(sd_match(Ctlz, m_Ctlz(m_Value())));
350+
EXPECT_TRUE(sd_match(Cttz, m_Cttz(m_Value())));
351+
EXPECT_FALSE(sd_match(Ctpop, m_Ctlz(m_Value())));
352+
EXPECT_FALSE(sd_match(Ctlz, m_Cttz(m_Value())));
353+
EXPECT_FALSE(sd_match(Cttz, m_Ctlz(m_Value())));
332354
}
333355

334356
TEST_F(SelectionDAGPatternMatchTest, matchConstants) {

0 commit comments

Comments
 (0)