Skip to content

Commit ee5ca4e

Browse files
committed
[AMDGPU] Remove combineAnd.
1 parent 70d8ac0 commit ee5ca4e

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
@@ -7061,84 +7061,6 @@ static unsigned getExtOpcodeForPromotedOp(SDValue Op) {
70617061
}
70627062
}
70637063

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

1537315295
SDValue SITargetLowering::PerformDAGCombine(SDNode *N,
1537415296
DAGCombinerInfo &DCI) const {
15375-
SelectionDAG &DAG = DCI.DAG;
1537615297
switch (N->getOpcode()) {
15377-
case ISD::AND:
15378-
if (auto Res = combineAnd(SDValue(N, 0), DCI))
15379-
return Res;
15380-
break;
1538115298
case ISD::ADD:
1538215299
case ISD::SUB:
1538315300
case ISD::SHL:
1538415301
case ISD::SRL:
1538515302
case ISD::SRA:
15303+
case ISD::AND:
1538615304
case ISD::OR:
1538715305
case ISD::XOR:
1538815306
case ISD::MUL:
@@ -15490,6 +15408,7 @@ SDValue SITargetLowering::PerformDAGCombine(SDNode *N,
1549015408
case AMDGPUISD::CLAMP:
1549115409
return performClampCombine(N, DCI);
1549215410
case ISD::SCALAR_TO_VECTOR: {
15411+
SelectionDAG &DAG = DCI.DAG;
1549315412
EVT VT = N->getValueType(0);
1549415413

1549515414
// v2i16 (scalar_to_vector i16:x) -> v2i16 (bitcast (any_extend i16:x))
@@ -17662,7 +17581,7 @@ SITargetLowering::lowerIdempotentRMWIntoFencedLoad(AtomicRMWInst *AI) const {
1766217581
bool SITargetLowering::hasAndNot(SDValue Op) const {
1766317582
// Return false if the operation is divergent, as AND-NOT is a scalar-only
1766417583
// instruction.
17665-
if (Op->isDivergent())
17584+
if (Op->isDivergent() || !Op->isMachineOpcode())
1766617585
return false;
1766717586

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