Skip to content

Commit b448b13

Browse files
committed
[AMDGPU] Remove combineAnd.
1 parent 92427f6 commit b448b13

File tree

4 files changed

+47
-124
lines changed

4 files changed

+47
-124
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -7029,84 +7029,6 @@ static unsigned getExtOpcodeForPromotedOp(SDValue Op) {
70297029
}
70307030
}
70317031

7032-
SDValue SITargetLowering::combineAnd(SDValue Op, DAGCombinerInfo &DCI) const {
7033-
const unsigned Opc = Op.getOpcode();
7034-
assert(Opc == ISD::AND);
7035-
7036-
auto &DAG = DCI.DAG;
7037-
SDLoc DL(Op);
7038-
7039-
if (hasAndNot(Op)) {
7040-
SDValue LHS = Op->getOperand(0);
7041-
SDValue RHS = Op->getOperand(1);
7042-
7043-
// (and LHS, (or Y, ~Z))
7044-
if (RHS.getOpcode() == ISD::OR && RHS.hasOneUse()) {
7045-
SDValue Y = RHS->getOperand(0);
7046-
SDValue NotZ = RHS->getOperand(1);
7047-
7048-
if (NotZ.getOpcode() == ISD::XOR &&
7049-
isAllOnesConstant(NotZ->getOperand(1))) {
7050-
SDValue Z = NotZ->getOperand(0);
7051-
7052-
if (!isa<ConstantSDNode>(Y)) {
7053-
SDValue NotY = DAG.getNOT(DL, Y, Y.getValueType());
7054-
SDValue AndNotYZ =
7055-
DAG.getNode(ISD::AND, DL, Y.getValueType(), NotY, Z);
7056-
SDValue NotAndNotYZ =
7057-
DAG.getNOT(DL, AndNotYZ, AndNotYZ.getValueType());
7058-
SDValue NewAnd =
7059-
DAG.getNode(ISD::AND, DL, Op.getValueType(), LHS, NotAndNotYZ);
7060-
return NewAnd;
7061-
}
7062-
}
7063-
}
7064-
}
7065-
7066-
EVT OpTy = (Opc != ISD::SETCC) ? Op.getValueType()
7067-
: Op->getOperand(0).getValueType();
7068-
auto ExtTy = OpTy.changeElementType(MVT::i32);
7069-
7070-
if (DCI.isBeforeLegalizeOps() ||
7071-
isNarrowingProfitable(Op.getNode(), ExtTy, OpTy))
7072-
return SDValue();
7073-
7074-
SDValue LHS;
7075-
SDValue RHS;
7076-
if (Opc == ISD::SELECT) {
7077-
LHS = Op->getOperand(1);
7078-
RHS = Op->getOperand(2);
7079-
} else {
7080-
LHS = Op->getOperand(0);
7081-
RHS = Op->getOperand(1);
7082-
}
7083-
7084-
const unsigned ExtOp = getExtOpcodeForPromotedOp(Op);
7085-
LHS = DAG.getNode(ExtOp, DL, ExtTy, {LHS});
7086-
7087-
// Special case: for shifts, the RHS always needs a zext.
7088-
if (Opc == ISD::SHL || Opc == ISD::SRL || Opc == ISD::SRA)
7089-
RHS = DAG.getNode(ISD::ZERO_EXTEND, DL, ExtTy, {RHS});
7090-
else
7091-
RHS = DAG.getNode(ExtOp, DL, ExtTy, {RHS});
7092-
7093-
// setcc always return i1/i1 vec so no need to truncate after.
7094-
if (Opc == ISD::SETCC) {
7095-
ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
7096-
return DAG.getSetCC(DL, Op.getValueType(), LHS, RHS, CC);
7097-
}
7098-
7099-
// For other ops, we extend the operation's return type as well so we need to
7100-
// truncate back to the original type.
7101-
SDValue NewVal;
7102-
if (Opc == ISD::SELECT)
7103-
NewVal = DAG.getNode(ISD::SELECT, DL, ExtTy, {Op->getOperand(0), LHS, RHS});
7104-
else
7105-
NewVal = DAG.getNode(Opc, DL, ExtTy, {LHS, RHS});
7106-
7107-
return DAG.getZExtOrTrunc(NewVal, DL, OpTy);
7108-
}
7109-
71107032
SDValue SITargetLowering::promoteUniformOpToI32(SDValue Op,
71117033
DAGCombinerInfo &DCI) const {
71127034
const unsigned Opc = Op.getOpcode();
@@ -15322,17 +15244,13 @@ SDValue SITargetLowering::performClampCombine(SDNode *N,
1532215244

1532315245
SDValue SITargetLowering::PerformDAGCombine(SDNode *N,
1532415246
DAGCombinerInfo &DCI) const {
15325-
SelectionDAG &DAG = DCI.DAG;
1532615247
switch (N->getOpcode()) {
15327-
case ISD::AND:
15328-
if (auto Res = combineAnd(SDValue(N, 0), DCI))
15329-
return Res;
15330-
break;
1533115248
case ISD::ADD:
1533215249
case ISD::SUB:
1533315250
case ISD::SHL:
1533415251
case ISD::SRL:
1533515252
case ISD::SRA:
15253+
case ISD::AND:
1533615254
case ISD::OR:
1533715255
case ISD::XOR:
1533815256
case ISD::MUL:
@@ -15438,6 +15356,7 @@ SDValue SITargetLowering::PerformDAGCombine(SDNode *N,
1543815356
case AMDGPUISD::CLAMP:
1543915357
return performClampCombine(N, DCI);
1544015358
case ISD::SCALAR_TO_VECTOR: {
15359+
SelectionDAG &DAG = DCI.DAG;
1544115360
EVT VT = N->getValueType(0);
1544215361

1544315362
// v2i16 (scalar_to_vector i16:x) -> v2i16 (bitcast (any_extend i16:x))
@@ -17610,7 +17529,7 @@ SITargetLowering::lowerIdempotentRMWIntoFencedLoad(AtomicRMWInst *AI) const {
1761017529
bool SITargetLowering::hasAndNot(SDValue Op) const {
1761117530
// Return false if the operation is divergent, as AND-NOT is a scalar-only
1761217531
// instruction.
17613-
if (Op->isDivergent())
17532+
if (Op->isDivergent() || !Op->isMachineOpcode())
1761417533
return false;
1761517534

1761617535
EVT VT = Op.getValueType();

llvm/lib/Target/AMDGPU/SIISelLowering.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ class SITargetLowering final : public AMDGPUTargetLowering {
148148
SDValue lowerFMINNUM_FMAXNUM(SDValue Op, SelectionDAG &DAG) const;
149149
SDValue lowerFMINIMUM_FMAXIMUM(SDValue Op, SelectionDAG &DAG) const;
150150
SDValue lowerFLDEXP(SDValue Op, SelectionDAG &DAG) const;
151-
SDValue combineAnd(SDValue Op, DAGCombinerInfo &DCI) const;
152151
SDValue promoteUniformOpToI32(SDValue Op, DAGCombinerInfo &DCI) const;
153152
SDValue lowerMUL(SDValue Op, SelectionDAG &DAG) const;
154153
SDValue lowerXMULO(SDValue Op, SelectionDAG &DAG) const;

llvm/test/CodeGen/AMDGPU/andorn2.ll

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,28 @@ entry:
2525
ret void
2626
}
2727

28+
; GCN-LABEL: {{^}}scalar_andn2_i32_one_sgpr
29+
; GCN: s_andn2_b32
30+
define amdgpu_kernel void @scalar_andn2_i32_one_sgpr(
31+
ptr addrspace(1) %r0, i32 inreg %a, i32 inreg %b) {
32+
entry:
33+
%nb = xor i32 %b, -1
34+
%r0.val = and i32 %a, %nb
35+
store i32 %r0.val, ptr addrspace(1) %r0
36+
ret void
37+
}
38+
39+
; GCN-LABEL: {{^}}scalar_andn2_i64_one_sgpr
40+
; GCN: s_andn2_b64
41+
define amdgpu_kernel void @scalar_andn2_i64_one_sgpr(
42+
ptr addrspace(1) %r0, i64 inreg %a, i64 inreg %b) {
43+
entry:
44+
%nb = xor i64 %b, -1
45+
%r0.val = and i64 %a, %nb
46+
store i64 %r0.val, ptr addrspace(1) %r0
47+
ret void
48+
}
49+
2850
; GCN-LABEL: {{^}}scalar_orn2_i32_one_use
2951
; GCN: s_orn2_b32
3052
define amdgpu_kernel void @scalar_orn2_i32_one_use(
@@ -47,6 +69,28 @@ entry:
4769
ret void
4870
}
4971

72+
; GCN-LABEL: {{^}}scalar_orn2_i32_one_use_sgpr
73+
; GCN: s_orn2_b32
74+
define amdgpu_kernel void @scalar_orn2_i32_one_use_sgpr(
75+
ptr addrspace(1) %r0, i32 inreg %a, i32 inreg %b) {
76+
entry:
77+
%nb = xor i32 %b, -1
78+
%r0.val = or i32 %a, %nb
79+
store i32 %r0.val, ptr addrspace(1) %r0
80+
ret void
81+
}
82+
83+
; GCN-LABEL: {{^}}scalar_orn2_i64_one_use_sgpr
84+
; GCN: s_orn2_b64
85+
define amdgpu_kernel void @scalar_orn2_i64_one_use_sgpr(
86+
ptr addrspace(1) %r0, i64 inreg %a, i64 inreg %b) {
87+
entry:
88+
%nb = xor i64 %b, -1
89+
%r0.val = or i64 %a, %nb
90+
store i64 %r0.val, ptr addrspace(1) %r0
91+
ret void
92+
}
93+
5094
; GCN-LABEL: {{^}}vector_andn2_i32_s_v_one_use
5195
; GCN: v_not_b32
5296
; GCN: v_and_b32

llvm/test/CodeGen/AMDGPU/andornot.ll

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)