Skip to content

Commit 24a8c2e

Browse files
committed
DAG: Combine AssertZext with and AssertSext
#142898 (comment)
1 parent 4881533 commit 24a8c2e

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14933,6 +14933,25 @@ SDValue DAGCombiner::visitAssertExt(SDNode *N) {
1493314933
}
1493414934
}
1493514935

14936+
// If we have (AssertZext (and (AssertSext X, iX), M), iY) and Y is smaller
14937+
// than X, and the And doesn't change the lower iY bits, we can move the
14938+
// AssertZext in front of the And and drop the AssertSext.
14939+
if (Opcode == ISD::AssertZext && N0.getOpcode() == ISD::AND &&
14940+
N0.hasOneUse() && N0.getOperand(0).getOpcode() == ISD::AssertSext &&
14941+
isa<ConstantSDNode>(N0.getOperand(1))) {
14942+
SDValue BigA = N0.getOperand(0);
14943+
EVT BigA_AssertVT = cast<VTSDNode>(BigA.getOperand(1))->getVT();
14944+
const APInt &Mask = N0.getConstantOperandAPInt(1);
14945+
if (AssertVT.bitsLT(BigA_AssertVT) &&
14946+
Mask.countr_one() >= AssertVT.getScalarSizeInBits()) {
14947+
SDLoc DL(N);
14948+
SDValue NewAssert =
14949+
DAG.getNode(Opcode, DL, N->getValueType(0), BigA.getOperand(0), N1);
14950+
return DAG.getNode(ISD::AND, DL, N->getValueType(0), NewAssert,
14951+
N0.getOperand(1));
14952+
}
14953+
}
14954+
1493614955
return SDValue();
1493714956
}
1493814957

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,7 @@ void TargetLowering::softenSetCCOperands(SelectionDAG &DAG, EVT VT,
434434

435435
EVT SetCCVT =
436436
getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), RetVT);
437-
if (RetVT == SetCCVT &&
438-
getBooleanContents(RetVT) == ZeroOrOneBooleanContent) {
439-
// FIXME: Checking the type matches is a hack in case the calling
440-
// convention lowering inserted some instructions after the
441-
// CopyFromReg. Combines fail to look through the AssertZext.
437+
if (getBooleanContents(RetVT) == ZeroOrOneBooleanContent) {
442438
NewLHS = DAG.getNode(ISD::AssertZext, dl, RetVT, Call.first,
443439
DAG.getValueType(MVT::i1));
444440
}

0 commit comments

Comments
 (0)