Skip to content

Commit 10651fa

Browse files
committed
Remove fold with unhandeable corner case
1 parent 76dae60 commit 10651fa

File tree

2 files changed

+22
-47
lines changed

2 files changed

+22
-47
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,11 +2627,11 @@ SDValue DAGCombiner::visitPTRADD(SDNode *N) {
26272627
EVT IntVT = N1.getValueType();
26282628
SDLoc DL(N);
26292629

2630-
// fold (ptradd und*f, y) -> und*f
2630+
// fold (ptradd undef, y) -> undef
26312631
if (N0.isUndef())
26322632
return N0;
26332633

2634-
// fold (ptradd x, und*f) -> und*f
2634+
// fold (ptradd x, undef) -> undef
26352635
if (N1.isUndef())
26362636
return DAG.getUNDEF(PtrVT);
26372637

@@ -2647,33 +2647,6 @@ SDValue DAGCombiner::visitPTRADD(SDNode *N) {
26472647
bool N0OneUse = N0.hasOneUse();
26482648
bool YIsConstant = DAG.isConstantIntBuildVectorOrConstantInt(Y);
26492649
bool ZIsConstant = DAG.isConstantIntBuildVectorOrConstantInt(Z);
2650-
2651-
// (ptradd (ptradd x, y), z) -> (ptradd (ptradd x, z), y) if:
2652-
// * (ptradd x, y) has one use; and
2653-
// * y is a constant; and
2654-
// * z is not a constant.
2655-
// Serves to expose constant y for subsequent folding.
2656-
if (N0OneUse && YIsConstant && !ZIsConstant) {
2657-
SDValue Add = DAG.getNode(ISD::PTRADD, DL, IntVT, {X, Z});
2658-
2659-
// Calling visit() can replace the Add node with ISD::DELETED_NODE if
2660-
// there aren't any users, so keep a handle around whilst we visit it.
2661-
HandleSDNode ADDHandle(Add);
2662-
2663-
SDValue VisitedAdd = visit(Add.getNode());
2664-
if (VisitedAdd) {
2665-
// If visit() returns the same node, it means the SDNode was RAUW'd, and
2666-
// therefore we have to load the new value to perform the checks whether
2667-
// the reassociation fold is profitable.
2668-
if (VisitedAdd.getNode() == Add.getNode())
2669-
Add = ADDHandle.getValue();
2670-
else
2671-
Add = VisitedAdd;
2672-
}
2673-
2674-
return DAG.getMemBasePlusOffset(Add, Y, DL, SDNodeFlags());
2675-
}
2676-
26772650
bool ZOneUse = Z.hasOneUse();
26782651

26792652
// (ptradd (ptradd x, y), z) -> (ptradd x, (add y, z)) if:

llvm/test/CodeGen/AArch64/cpa-selectiondag.ll

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,20 @@ entry:
6262

6363
define void @msubpt1(i32 %index, i32 %elem) {
6464
; CHECK-CPA-O0-LABEL: msubpt1:
65-
; CHECK-CPA-O0: addpt [[REG1:x[0-9]+]], x{{[0-9]+}}, x{{[0-9]+}}, lsl #4
66-
; CHECK-CPA-O0: addpt [[REG2:x[0-9]+]], [[REG1]], x{{[0-9]+}}
67-
; CHECK-CPA-O0: addpt [[REG3:x[0-9]+]], x{{[0-9]+}}, x{{[0-9]+}}
68-
; CHECK-CPA-O0: ldr q{{[0-9]+}}, [[[REG3]], #16]
69-
; CHECK-CPA-O0: str q{{[0-9]+}}, [[[REG1]], #288]
70-
; CHECK-CPA-O0: str q{{[0-9]+}}, [[[REG2]], #32]
65+
; CHECK-CPA-O0: addpt [[REG1:x[0-9]+]], x{{[0-9]+}}, [[REG1]]
66+
; CHECK-CPA-O0: addpt [[REG2:x[0-9]+]], x{{[0-9]+}}, [[REG2]]
67+
; CHECK-CPA-O0: ldr q{{[0-9]+}}, [[[REG2]], #16]
68+
; CHECK-CPA-O0: ldr q{{[0-9]+}}, [[[REG2]], #32]
69+
; CHECK-CPA-O0: str q{{[0-9]+}}, [[[REG1]], #32]
70+
; CHECK-CPA-O0: str q{{[0-9]+}}, [[[REG1]], #16]
71+
; CHECK-CPA-O0: str q{{[0-9]+}}, [[[REG1]]]
7172
;
7273
; CHECK-CPA-O3-LABEL: msubpt1:
73-
; CHECK-CPA-O3: addpt [[REG1:x[0-9]+]], x{{[0-9]+}}, x{{[0-9]+}}, lsl #4
74-
; CHECK-CPA-O3: addpt [[REG2:x[0-9]+]], [[REG1]], x{{[0-9]+}}
75-
; CHECK-CPA-O3: str q{{[0-9]+}}, [[[REG1]], #288]
74+
; CHECK-CPA-O3: addpt [[REG1:x[0-9]+]], x{{[0-9]+}}, [[REG1]]
75+
; CHECK-CPA-O3: ldp q{{[0-9]+}}, q{{[0-9]+}}, [[[REG1]], #16]
76+
; CHECK-CPA-O3: addpt [[REG2:x[0-9]+]], x{{[0-9]+}}, [[REG2]]
7677
; CHECK-CPA-O3: stp q{{[0-9]+}}, q{{[0-9]+}}, [[[REG2]], #16]
78+
; CHECK-CPA-O3: str q{{[0-9]+}}, [[[REG2]]]
7779
;
7880
; CHECK-NOCPA-O0-LABEL: msubpt1:
7981
; CHECK-NOCPA-O0: mneg [[REG1:x[0-9]+]], x{{[0-9]+}}, x{{[0-9]+}}
@@ -97,12 +99,12 @@ entry:
9799

98100
define void @subpt1(i32 %index, i32 %elem) {
99101
; CHECK-CPA-O0-LABEL: subpt1:
100-
; CHECK-CPA-O0: subpt [[REG1:x[0-9]+]], x{{[0-9]+}}, x{{[0-9]+}}
101-
; CHECK-CPA-O0: str q{{[0-9]+}}, [[[REG1]], #96]
102+
; CHECK-CPA-O0: addpt [[REG1:x[0-9]+]], x{{[0-9]+}}, [[REG1]]
103+
; CHECK-CPA-O0: str q{{[0-9]+}}, [[[REG1]]]
102104
;
103105
; CHECK-CPA-O3-LABEL: subpt1:
104-
; CHECK-CPA-O3: subpt [[REG1:x[0-9]+]], x{{[0-9]+}}, x{{[0-9]+}}
105-
; CHECK-CPA-O3: str q{{[0-9]+}}, [[[REG1]], #96]
106+
; CHECK-CPA-O3: addpt [[REG1:x[0-9]+]], x{{[0-9]+}}, [[REG1]]
107+
; CHECK-CPA-O3: str q{{[0-9]+}}, [[[REG1]]]
106108
;
107109
; CHECK-NOCPA-O0-LABEL: subpt1:
108110
; CHECK-NOCPA-O0: subs [[REG1:x[0-9]+]], x{{[0-9]+}}, x{{[0-9]+}}, lsl #8
@@ -121,12 +123,12 @@ entry:
121123

122124
define void @subpt2(i32 %index, i32 %elem) {
123125
; CHECK-CPA-O0-LABEL: subpt2:
124-
; CHECK-CPA-O0: addpt [[REG1:x[0-9]+]], x{{[0-9]+}}, x{{[0-9]+}}, lsl #4
125-
; CHECK-CPA-O0: str q{{[0-9]+}}, [[[REG1]], #96]
126+
; CHECK-CPA-O0: addpt [[REG1:x[0-9]+]], x{{[0-9]+}}, [[REG1]]
127+
; CHECK-CPA-O0: str q{{[0-9]+}}, [[[REG1]]]
126128
;
127129
; CHECK-CPA-O3-LABEL: subpt2:
128-
; CHECK-CPA-O3: addpt [[REG1:x[0-9]+]], x{{[0-9]+}}, x{{[0-9]+}}, lsl #4
129-
; CHECK-CPA-O3: str q{{[0-9]+}}, [[[REG1]], #96]
130+
; CHECK-CPA-O3: addpt [[REG1:x[0-9]+]], x{{[0-9]+}}, [[REG1]]
131+
; CHECK-CPA-O3: str q{{[0-9]+}}, [[[REG1]]]
130132
;
131133
; CHECK-NOCPA-O0-LABEL: subpt2:
132134
; CHECK-NOCPA-O0: subs [[REG1:x[0-9]+]], x{{[0-9]+}}, w{{[0-9]+}}, sxtw #4
@@ -401,7 +403,7 @@ define hidden void @multidim() {
401403
; CHECK-CPA-O0: mov w9, w9
402404
; CHECK-CPA-O0: add x9, x9, w10, uxtw #1
403405
; CHECK-CPA-O0: addpt x8, x8, x9
404-
; CHECK-CPA-O0: ldrb w8, [x8, #2]
406+
; CHECK-CPA-O0: ldrb w8, [x8]
405407
;
406408
; CHECK-CPA-O3-LABEL: multidim:
407409
; CHECK-CPA-O3: ret

0 commit comments

Comments
 (0)