Skip to content

Commit cb71724

Browse files
committed
Implement reviewer suggestions
1 parent b87fccc commit cb71724

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,7 +2652,7 @@ SDValue DAGCombiner::visitPTRADD(SDNode *N) {
26522652
return N0;
26532653

26542654
// fold (ptradd 0, x) -> x
2655-
if (isNullConstant(N0) && PtrVT == IntVT)
2655+
if (PtrVT == IntVT && isNullConstant(N0))
26562656
return N1;
26572657

26582658
if (N0.getOpcode() != ISD::PTRADD ||
@@ -2670,10 +2670,9 @@ SDValue DAGCombiner::visitPTRADD(SDNode *N) {
26702670
// * y is a constant and (ptradd x, y) has one use; or
26712671
// * y and z are both constants.
26722672
if ((YIsConstant && N0OneUse) || (YIsConstant && ZIsConstant)) {
2673-
SDNodeFlags Flags;
26742673
// If both additions in the original were NUW, the new ones are as well.
2675-
if (N->getFlags().hasNoUnsignedWrap() && N0->getFlags().hasNoUnsignedWrap())
2676-
Flags |= SDNodeFlags::NoUnsignedWrap;
2674+
SDNodeFlags Flags =
2675+
(N->getFlags() & N0->getFlags()) & SDNodeFlags::NoUnsignedWrap;
26772676
SDValue Add = DAG.getNode(ISD::ADD, DL, IntVT, {Y, Z}, Flags);
26782677
AddToWorklist(Add.getNode());
26792678
return DAG.getMemBasePlusOffset(X, Add, DL, Flags);

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15119,22 +15119,20 @@ SDValue SITargetLowering::performPtrAddCombine(SDNode *N,
1511915119
SDValue X = N0;
1512015120
SDValue Y = N1.getOperand(0);
1512115121
SDValue Z = N1.getOperand(1);
15122-
bool N1OneUse = N1.hasOneUse();
15123-
bool YIsConstant = DAG.isConstantIntBuildVectorOrConstantInt(Y);
15124-
bool ZIsConstant = DAG.isConstantIntBuildVectorOrConstantInt(Z);
15125-
if ((ZIsConstant != YIsConstant) && N1OneUse) {
15126-
SDNodeFlags Flags;
15127-
// If both additions in the original were NUW, the new ones are as well.
15128-
if (N->getFlags().hasNoUnsignedWrap() &&
15129-
N1->getFlags().hasNoUnsignedWrap())
15130-
Flags |= SDNodeFlags::NoUnsignedWrap;
15131-
15132-
if (YIsConstant)
15133-
std::swap(Y, Z);
15134-
15135-
SDValue Inner = DAG.getMemBasePlusOffset(X, Y, DL, Flags);
15136-
DCI.AddToWorklist(Inner.getNode());
15137-
return DAG.getMemBasePlusOffset(Inner, Z, DL, Flags);
15122+
if (N1.hasOneUse()) {
15123+
bool YIsConstant = DAG.isConstantIntBuildVectorOrConstantInt(Y);
15124+
bool ZIsConstant = DAG.isConstantIntBuildVectorOrConstantInt(Z);
15125+
if (ZIsConstant != YIsConstant) {
15126+
// If both additions in the original were NUW, the new ones are as well.
15127+
SDNodeFlags Flags =
15128+
(N->getFlags() & N1->getFlags()) & SDNodeFlags::NoUnsignedWrap;
15129+
if (YIsConstant)
15130+
std::swap(Y, Z);
15131+
15132+
SDValue Inner = DAG.getMemBasePlusOffset(X, Y, DL, Flags);
15133+
DCI.AddToWorklist(Inner.getNode());
15134+
return DAG.getMemBasePlusOffset(Inner, Z, DL, Flags);
15135+
}
1513815136
}
1513915137
}
1514015138

0 commit comments

Comments
 (0)