Skip to content

Commit e773ffd

Browse files
committed
[AMDGPU] Remove combineAnd.
1 parent c7ea3c9 commit e773ffd

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
@@ -7049,84 +7049,6 @@ static unsigned getExtOpcodeForPromotedOp(SDValue Op) {
70497049
}
70507050
}
70517051

7052-
SDValue SITargetLowering::combineAnd(SDValue Op, DAGCombinerInfo &DCI) const {
7053-
const unsigned Opc = Op.getOpcode();
7054-
assert(Opc == ISD::AND);
7055-
7056-
auto &DAG = DCI.DAG;
7057-
SDLoc DL(Op);
7058-
7059-
if (hasAndNot(Op)) {
7060-
SDValue LHS = Op->getOperand(0);
7061-
SDValue RHS = Op->getOperand(1);
7062-
7063-
// (and LHS, (or Y, ~Z))
7064-
if (RHS.getOpcode() == ISD::OR && RHS.hasOneUse()) {
7065-
SDValue Y = RHS->getOperand(0);
7066-
SDValue NotZ = RHS->getOperand(1);
7067-
7068-
if (NotZ.getOpcode() == ISD::XOR &&
7069-
isAllOnesConstant(NotZ->getOperand(1))) {
7070-
SDValue Z = NotZ->getOperand(0);
7071-
7072-
if (!isa<ConstantSDNode>(Y)) {
7073-
SDValue NotY = DAG.getNOT(DL, Y, Y.getValueType());
7074-
SDValue AndNotYZ =
7075-
DAG.getNode(ISD::AND, DL, Y.getValueType(), NotY, Z);
7076-
SDValue NotAndNotYZ =
7077-
DAG.getNOT(DL, AndNotYZ, AndNotYZ.getValueType());
7078-
SDValue NewAnd =
7079-
DAG.getNode(ISD::AND, DL, Op.getValueType(), LHS, NotAndNotYZ);
7080-
return NewAnd;
7081-
}
7082-
}
7083-
}
7084-
}
7085-
7086-
EVT OpTy = (Opc != ISD::SETCC) ? Op.getValueType()
7087-
: Op->getOperand(0).getValueType();
7088-
auto ExtTy = OpTy.changeElementType(MVT::i32);
7089-
7090-
if (DCI.isBeforeLegalizeOps() ||
7091-
isNarrowingProfitable(Op.getNode(), ExtTy, OpTy))
7092-
return SDValue();
7093-
7094-
SDValue LHS;
7095-
SDValue RHS;
7096-
if (Opc == ISD::SELECT) {
7097-
LHS = Op->getOperand(1);
7098-
RHS = Op->getOperand(2);
7099-
} else {
7100-
LHS = Op->getOperand(0);
7101-
RHS = Op->getOperand(1);
7102-
}
7103-
7104-
const unsigned ExtOp = getExtOpcodeForPromotedOp(Op);
7105-
LHS = DAG.getNode(ExtOp, DL, ExtTy, {LHS});
7106-
7107-
// Special case: for shifts, the RHS always needs a zext.
7108-
if (Opc == ISD::SHL || Opc == ISD::SRL || Opc == ISD::SRA)
7109-
RHS = DAG.getNode(ISD::ZERO_EXTEND, DL, ExtTy, {RHS});
7110-
else
7111-
RHS = DAG.getNode(ExtOp, DL, ExtTy, {RHS});
7112-
7113-
// setcc always return i1/i1 vec so no need to truncate after.
7114-
if (Opc == ISD::SETCC) {
7115-
ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
7116-
return DAG.getSetCC(DL, Op.getValueType(), LHS, RHS, CC);
7117-
}
7118-
7119-
// For other ops, we extend the operation's return type as well so we need to
7120-
// truncate back to the original type.
7121-
SDValue NewVal;
7122-
if (Opc == ISD::SELECT)
7123-
NewVal = DAG.getNode(ISD::SELECT, DL, ExtTy, {Op->getOperand(0), LHS, RHS});
7124-
else
7125-
NewVal = DAG.getNode(Opc, DL, ExtTy, {LHS, RHS});
7126-
7127-
return DAG.getZExtOrTrunc(NewVal, DL, OpTy);
7128-
}
7129-
71307052
SDValue SITargetLowering::promoteUniformOpToI32(SDValue Op,
71317053
DAGCombinerInfo &DCI) const {
71327054
const unsigned Opc = Op.getOpcode();
@@ -15356,17 +15278,13 @@ SDValue SITargetLowering::performClampCombine(SDNode *N,
1535615278

1535715279
SDValue SITargetLowering::PerformDAGCombine(SDNode *N,
1535815280
DAGCombinerInfo &DCI) const {
15359-
SelectionDAG &DAG = DCI.DAG;
1536015281
switch (N->getOpcode()) {
15361-
case ISD::AND:
15362-
if (auto Res = combineAnd(SDValue(N, 0), DCI))
15363-
return Res;
15364-
break;
1536515282
case ISD::ADD:
1536615283
case ISD::SUB:
1536715284
case ISD::SHL:
1536815285
case ISD::SRL:
1536915286
case ISD::SRA:
15287+
case ISD::AND:
1537015288
case ISD::OR:
1537115289
case ISD::XOR:
1537215290
case ISD::MUL:
@@ -15474,6 +15392,7 @@ SDValue SITargetLowering::PerformDAGCombine(SDNode *N,
1547415392
case AMDGPUISD::CLAMP:
1547515393
return performClampCombine(N, DCI);
1547615394
case ISD::SCALAR_TO_VECTOR: {
15395+
SelectionDAG &DAG = DCI.DAG;
1547715396
EVT VT = N->getValueType(0);
1547815397

1547915398
// v2i16 (scalar_to_vector i16:x) -> v2i16 (bitcast (any_extend i16:x))
@@ -17646,7 +17565,7 @@ SITargetLowering::lowerIdempotentRMWIntoFencedLoad(AtomicRMWInst *AI) const {
1764617565
bool SITargetLowering::hasAndNot(SDValue Op) const {
1764717566
// Return false if the operation is divergent, as AND-NOT is a scalar-only
1764817567
// instruction.
17649-
if (Op->isDivergent())
17568+
if (Op->isDivergent() || !Op->isMachineOpcode())
1765017569
return false;
1765117570

1765217571
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)