Skip to content

Commit ff1af1b

Browse files
committed
[DAG] visitORCommutative - fold build_pair(not(x),not(y)) -> not(build_pair(x,y)) style patterns
(Sorry, not an actual build_pair node just a similar pattern). For cases where we're concatenating 2 integers into a double width integer, see if both integer sources are NOT patterns. We could take this further and handle all logic ops with a constant operands, but I just wanted to handle the case reported on #89533 initially. Fixes #89533
1 parent ef2ca97 commit ff1af1b

File tree

2 files changed

+29
-48
lines changed

2 files changed

+29
-48
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7620,6 +7620,7 @@ SDValue DAGCombiner::visitORLike(SDValue N0, SDValue N1, const SDLoc &DL) {
76207620
static SDValue visitORCommutative(SelectionDAG &DAG, SDValue N0, SDValue N1,
76217621
SDNode *N) {
76227622
EVT VT = N0.getValueType();
7623+
unsigned BW = VT.getScalarSizeInBits();
76237624
SDLoc DL(N);
76247625

76257626
auto peekThroughResize = [](SDValue V) {
@@ -7689,6 +7690,26 @@ static SDValue visitORCommutative(SelectionDAG &DAG, SDValue N0, SDValue N1,
76897690
peekThroughZext(N0.getOperand(2)) == peekThroughZext(N1.getOperand(1)))
76907691
return N0;
76917692

7693+
// Attempt to match a legalized build_pair-esque pattern:
7694+
// or(shl(aext(X),BW/2),zext(Y))
7695+
SDValue Lo, Hi;
7696+
if (sd_match(N0,
7697+
m_OneUse(m_Shl(m_AnyExt(m_Value(Hi)), m_SpecificInt(BW / 2)))) &&
7698+
sd_match(N1, m_ZExt(m_Value(Lo))) &&
7699+
Lo.getScalarValueSizeInBits() == (BW / 2) &&
7700+
Lo.getValueType() == Hi.getValueType()) {
7701+
// Fold build_pair(not(Lo),not(Hi)) -> not(build_pair(Lo,Hi)).
7702+
SDValue NotLo, NotHi;
7703+
if (sd_match(Lo, m_OneUse(m_Not(m_Value(NotLo)))) &&
7704+
sd_match(Hi, m_OneUse(m_Not(m_Value(NotHi))))) {
7705+
Lo = DAG.getZExtOrTrunc(NotLo, DL, VT);
7706+
Hi = DAG.getZExtOrTrunc(NotHi, DL, VT);
7707+
Hi = DAG.getNode(ISD::SHL, DL, VT, Hi,
7708+
DAG.getShiftAmountConstant(BW / 2, VT, DL));
7709+
return DAG.getNOT(DL, DAG.getNode(ISD::OR, DL, VT, Lo, Hi), VT);
7710+
}
7711+
}
7712+
76927713
return SDValue();
76937714
}
76947715

llvm/test/CodeGen/X86/subvectorwise-store-of-vector-splat.ll

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,12 +3060,7 @@ define void @vec384_v3i32(ptr %in.subvec.ptr, ptr %out.subvec.ptr, ptr %out.vec.
30603060
; SCALAR: # %bb.0:
30613061
; SCALAR-NEXT: movl 8(%rdi), %eax
30623062
; SCALAR-NEXT: movq (%rdi), %rcx
3063-
; SCALAR-NEXT: movq %rcx, %rdi
3064-
; SCALAR-NEXT: shrq $32, %rdi
3065-
; SCALAR-NEXT: notl %edi
3066-
; SCALAR-NEXT: shlq $32, %rdi
3067-
; SCALAR-NEXT: notl %ecx
3068-
; SCALAR-NEXT: orq %rdi, %rcx
3063+
; SCALAR-NEXT: notq %rcx
30693064
; SCALAR-NEXT: notl %eax
30703065
; SCALAR-NEXT: movl %eax, 8(%rsi)
30713066
; SCALAR-NEXT: movq %rcx, (%rsi)
@@ -3196,12 +3191,7 @@ define void @vec384_v3f32(ptr %in.subvec.ptr, ptr %out.subvec.ptr, ptr %out.vec.
31963191
; SCALAR: # %bb.0:
31973192
; SCALAR-NEXT: movl 8(%rdi), %eax
31983193
; SCALAR-NEXT: movq (%rdi), %rcx
3199-
; SCALAR-NEXT: movq %rcx, %rdi
3200-
; SCALAR-NEXT: shrq $32, %rdi
3201-
; SCALAR-NEXT: notl %edi
3202-
; SCALAR-NEXT: shlq $32, %rdi
3203-
; SCALAR-NEXT: notl %ecx
3204-
; SCALAR-NEXT: orq %rdi, %rcx
3194+
; SCALAR-NEXT: notq %rcx
32053195
; SCALAR-NEXT: notl %eax
32063196
; SCALAR-NEXT: movl %eax, 8(%rsi)
32073197
; SCALAR-NEXT: movq %rcx, (%rsi)
@@ -4216,25 +4206,10 @@ define void @vec384_v6i32(ptr %in.subvec.ptr, ptr %out.subvec.ptr, ptr %out.vec.
42164206
; SCALAR: # %bb.0:
42174207
; SCALAR-NEXT: movq (%rdi), %rax
42184208
; SCALAR-NEXT: movq 8(%rdi), %rcx
4219-
; SCALAR-NEXT: movq %rax, %r8
4220-
; SCALAR-NEXT: shrq $32, %r8
4221-
; SCALAR-NEXT: movq %rcx, %r9
4222-
; SCALAR-NEXT: shrq $32, %r9
42234209
; SCALAR-NEXT: movq 16(%rdi), %rdi
4224-
; SCALAR-NEXT: movq %rdi, %r10
4225-
; SCALAR-NEXT: shrq $32, %r10
4226-
; SCALAR-NEXT: notl %r10d
4227-
; SCALAR-NEXT: shlq $32, %r10
4228-
; SCALAR-NEXT: notl %edi
4229-
; SCALAR-NEXT: orq %r10, %rdi
4230-
; SCALAR-NEXT: notl %r9d
4231-
; SCALAR-NEXT: shlq $32, %r9
4232-
; SCALAR-NEXT: notl %ecx
4233-
; SCALAR-NEXT: orq %r9, %rcx
4234-
; SCALAR-NEXT: notl %r8d
4235-
; SCALAR-NEXT: shlq $32, %r8
4236-
; SCALAR-NEXT: notl %eax
4237-
; SCALAR-NEXT: orq %r8, %rax
4210+
; SCALAR-NEXT: notq %rdi
4211+
; SCALAR-NEXT: notq %rcx
4212+
; SCALAR-NEXT: notq %rax
42384213
; SCALAR-NEXT: movq %rax, (%rsi)
42394214
; SCALAR-NEXT: movq %rcx, 8(%rsi)
42404215
; SCALAR-NEXT: movq %rdi, 16(%rsi)
@@ -4303,25 +4278,10 @@ define void @vec384_v6f32(ptr %in.subvec.ptr, ptr %out.subvec.ptr, ptr %out.vec.
43034278
; SCALAR: # %bb.0:
43044279
; SCALAR-NEXT: movq (%rdi), %rax
43054280
; SCALAR-NEXT: movq 8(%rdi), %rcx
4306-
; SCALAR-NEXT: movq %rax, %r8
4307-
; SCALAR-NEXT: shrq $32, %r8
4308-
; SCALAR-NEXT: movq %rcx, %r9
4309-
; SCALAR-NEXT: shrq $32, %r9
43104281
; SCALAR-NEXT: movq 16(%rdi), %rdi
4311-
; SCALAR-NEXT: movq %rdi, %r10
4312-
; SCALAR-NEXT: shrq $32, %r10
4313-
; SCALAR-NEXT: notl %r10d
4314-
; SCALAR-NEXT: shlq $32, %r10
4315-
; SCALAR-NEXT: notl %edi
4316-
; SCALAR-NEXT: orq %r10, %rdi
4317-
; SCALAR-NEXT: notl %r9d
4318-
; SCALAR-NEXT: shlq $32, %r9
4319-
; SCALAR-NEXT: notl %ecx
4320-
; SCALAR-NEXT: orq %r9, %rcx
4321-
; SCALAR-NEXT: notl %r8d
4322-
; SCALAR-NEXT: shlq $32, %r8
4323-
; SCALAR-NEXT: notl %eax
4324-
; SCALAR-NEXT: orq %r8, %rax
4282+
; SCALAR-NEXT: notq %rdi
4283+
; SCALAR-NEXT: notq %rcx
4284+
; SCALAR-NEXT: notq %rax
43254285
; SCALAR-NEXT: movq %rax, (%rsi)
43264286
; SCALAR-NEXT: movq %rcx, 8(%rsi)
43274287
; SCALAR-NEXT: movq %rdi, 16(%rsi)

0 commit comments

Comments
 (0)