Skip to content

Commit ea08a49

Browse files
committed
[AMDGPU] Remove combineAnd.
1 parent e5e1c5f commit ea08a49

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
@@ -6822,84 +6822,6 @@ static unsigned getExtOpcodeForPromotedOp(SDValue Op) {
68226822
}
68236823
}
68246824

6825-
SDValue SITargetLowering::combineAnd(SDValue Op, DAGCombinerInfo &DCI) const {
6826-
const unsigned Opc = Op.getOpcode();
6827-
assert(Opc == ISD::AND);
6828-
6829-
auto &DAG = DCI.DAG;
6830-
SDLoc DL(Op);
6831-
6832-
if (hasAndNot(Op)) {
6833-
SDValue LHS = Op->getOperand(0);
6834-
SDValue RHS = Op->getOperand(1);
6835-
6836-
// (and LHS, (or Y, ~Z))
6837-
if (RHS.getOpcode() == ISD::OR && RHS.hasOneUse()) {
6838-
SDValue Y = RHS->getOperand(0);
6839-
SDValue NotZ = RHS->getOperand(1);
6840-
6841-
if (NotZ.getOpcode() == ISD::XOR &&
6842-
isAllOnesConstant(NotZ->getOperand(1))) {
6843-
SDValue Z = NotZ->getOperand(0);
6844-
6845-
if (!isa<ConstantSDNode>(Y)) {
6846-
SDValue NotY = DAG.getNOT(DL, Y, Y.getValueType());
6847-
SDValue AndNotYZ =
6848-
DAG.getNode(ISD::AND, DL, Y.getValueType(), NotY, Z);
6849-
SDValue NotAndNotYZ =
6850-
DAG.getNOT(DL, AndNotYZ, AndNotYZ.getValueType());
6851-
SDValue NewAnd =
6852-
DAG.getNode(ISD::AND, DL, Op.getValueType(), LHS, NotAndNotYZ);
6853-
return NewAnd;
6854-
}
6855-
}
6856-
}
6857-
}
6858-
6859-
EVT OpTy = (Opc != ISD::SETCC) ? Op.getValueType()
6860-
: Op->getOperand(0).getValueType();
6861-
auto ExtTy = OpTy.changeElementType(MVT::i32);
6862-
6863-
if (DCI.isBeforeLegalizeOps() ||
6864-
isNarrowingProfitable(Op.getNode(), ExtTy, OpTy))
6865-
return SDValue();
6866-
6867-
SDValue LHS;
6868-
SDValue RHS;
6869-
if (Opc == ISD::SELECT) {
6870-
LHS = Op->getOperand(1);
6871-
RHS = Op->getOperand(2);
6872-
} else {
6873-
LHS = Op->getOperand(0);
6874-
RHS = Op->getOperand(1);
6875-
}
6876-
6877-
const unsigned ExtOp = getExtOpcodeForPromotedOp(Op);
6878-
LHS = DAG.getNode(ExtOp, DL, ExtTy, {LHS});
6879-
6880-
// Special case: for shifts, the RHS always needs a zext.
6881-
if (Opc == ISD::SHL || Opc == ISD::SRL || Opc == ISD::SRA)
6882-
RHS = DAG.getNode(ISD::ZERO_EXTEND, DL, ExtTy, {RHS});
6883-
else
6884-
RHS = DAG.getNode(ExtOp, DL, ExtTy, {RHS});
6885-
6886-
// setcc always return i1/i1 vec so no need to truncate after.
6887-
if (Opc == ISD::SETCC) {
6888-
ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
6889-
return DAG.getSetCC(DL, Op.getValueType(), LHS, RHS, CC);
6890-
}
6891-
6892-
// For other ops, we extend the operation's return type as well so we need to
6893-
// truncate back to the original type.
6894-
SDValue NewVal;
6895-
if (Opc == ISD::SELECT)
6896-
NewVal = DAG.getNode(ISD::SELECT, DL, ExtTy, {Op->getOperand(0), LHS, RHS});
6897-
else
6898-
NewVal = DAG.getNode(Opc, DL, ExtTy, {LHS, RHS});
6899-
6900-
return DAG.getZExtOrTrunc(NewVal, DL, OpTy);
6901-
}
6902-
69036825
SDValue SITargetLowering::promoteUniformOpToI32(SDValue Op,
69046826
DAGCombinerInfo &DCI) const {
69056827
const unsigned Opc = Op.getOpcode();
@@ -14877,17 +14799,13 @@ SDValue SITargetLowering::performClampCombine(SDNode *N,
1487714799

1487814800
SDValue SITargetLowering::PerformDAGCombine(SDNode *N,
1487914801
DAGCombinerInfo &DCI) const {
14880-
SelectionDAG &DAG = DCI.DAG;
1488114802
switch (N->getOpcode()) {
14882-
case ISD::AND:
14883-
if (auto Res = combineAnd(SDValue(N, 0), DCI))
14884-
return Res;
14885-
break;
1488614803
case ISD::ADD:
1488714804
case ISD::SUB:
1488814805
case ISD::SHL:
1488914806
case ISD::SRL:
1489014807
case ISD::SRA:
14808+
case ISD::AND:
1489114809
case ISD::OR:
1489214810
case ISD::XOR:
1489314811
case ISD::MUL:
@@ -14991,6 +14909,7 @@ SDValue SITargetLowering::PerformDAGCombine(SDNode *N,
1499114909
case AMDGPUISD::CLAMP:
1499214910
return performClampCombine(N, DCI);
1499314911
case ISD::SCALAR_TO_VECTOR: {
14912+
SelectionDAG &DAG = DCI.DAG;
1499414913
EVT VT = N->getValueType(0);
1499514914

1499614915
// v2i16 (scalar_to_vector i16:x) -> v2i16 (bitcast (any_extend i16:x))
@@ -16974,7 +16893,7 @@ SITargetLowering::lowerIdempotentRMWIntoFencedLoad(AtomicRMWInst *AI) const {
1697416893
bool SITargetLowering::hasAndNot(SDValue Op) const {
1697516894
// Return false if the operation is divergent, as AND-NOT is a scalar-only
1697616895
// instruction.
16977-
if (Op->isDivergent())
16896+
if (Op->isDivergent() || !Op->isMachineOpcode())
1697816897
return false;
1697916898

1698016899
EVT VT = Op.getValueType();

llvm/lib/Target/AMDGPU/SIISelLowering.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ class SITargetLowering final : public AMDGPUTargetLowering {
147147
SDValue lowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
148148
SDValue lowerFMINNUM_FMAXNUM(SDValue Op, SelectionDAG &DAG) const;
149149
SDValue lowerFLDEXP(SDValue Op, SelectionDAG &DAG) const;
150-
SDValue combineAnd(SDValue Op, DAGCombinerInfo &DCI) const;
151150
SDValue promoteUniformOpToI32(SDValue Op, DAGCombinerInfo &DCI) const;
152151
SDValue lowerMUL(SDValue Op, SelectionDAG &DAG) const;
153152
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)