[llvm] 11aa95f - [DAG] visitSUB - pull out repeated getScalarSizeInBits() calls. NFC.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 21 02:56:03 PDT 2024
Author: Simon Pilgrim
Date: 2024-03-21T09:55:50Z
New Revision: 11aa95f83b7bf980ea13f1bb75e09af89a733acb
URL: https://github.com/llvm/llvm-project/commit/11aa95f83b7bf980ea13f1bb75e09af89a733acb
DIFF: https://github.com/llvm/llvm-project/commit/11aa95f83b7bf980ea13f1bb75e09af89a733acb.diff
LOG: [DAG] visitSUB - pull out repeated getScalarSizeInBits() calls. NFC.
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 1884722198829f..d370c57ce8e324 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -3695,6 +3695,7 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
SDValue N0 = N->getOperand(0);
SDValue N1 = N->getOperand(1);
EVT VT = N0.getValueType();
+ unsigned BitWidth = VT.getScalarSizeInBits();
SDLoc DL(N);
auto PeekThroughFreeze = [](SDValue N) {
@@ -3731,7 +3732,6 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
DAG.getConstant(-N1C->getAPIntValue(), DL, VT));
if (isNullOrNullSplat(N0)) {
- unsigned BitWidth = VT.getScalarSizeInBits();
// Right-shifting everything out but the sign bit followed by negation is
// the same as flipping arithmetic/logical shift type without the negation:
// -(X >>u 31) -> (X >>s 31)
@@ -3931,7 +3931,7 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
SDValue S0 = N1.getOperand(0);
if ((X0 == S0 && X1 == N1) || (X0 == N1 && X1 == S0))
if (ConstantSDNode *C = isConstOrConstSplat(N1.getOperand(1)))
- if (C->getAPIntValue() == (VT.getScalarSizeInBits() - 1))
+ if (C->getAPIntValue() == (BitWidth - 1))
return DAG.getNode(ISD::ABS, SDLoc(N), VT, S0);
}
}
@@ -3974,8 +3974,7 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
if (!LegalOperations && N1.getOpcode() == ISD::SRL && N1.hasOneUse()) {
SDValue ShAmt = N1.getOperand(1);
ConstantSDNode *ShAmtC = isConstOrConstSplat(ShAmt);
- if (ShAmtC &&
- ShAmtC->getAPIntValue() == (N1.getScalarValueSizeInBits() - 1)) {
+ if (ShAmtC && ShAmtC->getAPIntValue() == (BitWidth - 1)) {
SDValue SRA = DAG.getNode(ISD::SRA, DL, VT, N1.getOperand(0), ShAmt);
return DAG.getNode(ISD::ADD, DL, VT, N0, SRA);
}
@@ -3986,7 +3985,7 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
// N0 - (X << BW-1) --> N0 + (X << BW-1)
if (N1.getOpcode() == ISD::SHL) {
ConstantSDNode *ShlC = isConstOrConstSplat(N1.getOperand(1));
- if (ShlC && ShlC->getAPIntValue() == VT.getScalarSizeInBits() - 1)
+ if (ShlC && ShlC->getAPIntValue() == (BitWidth - 1))
return DAG.getNode(ISD::ADD, DL, VT, N1, N0);
}
More information about the llvm-commits
mailing list