[llvm] [DAG] Add TRUNCATE_SSAT_S/U and TRUNCATE_USAT_U to canCreateUndefOrPoison and computeKnownBits (#152143) (PR #168809)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 23 23:44:38 PST 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 781d7946e..8700fda09 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -3957,37 +3957,39 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
break;
}
case ISD::TRUNCATE_SSAT_S: {
- // Pass through DemandedElts to the recursive call
- KnownBits InputKnown = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
- unsigned InputBits = InputKnown.getBitWidth();
-
- APInt MinInRange = APInt::getSignedMinValue(BitWidth).sext(InputBits);
- APInt MaxInRange = APInt::getSignedMaxValue(BitWidth).sext(InputBits);
- APInt InputMin = InputKnown.getSignedMinValue();
- APInt InputMax = InputKnown.getSignedMaxValue();
-
- if (InputMin.sge(MinInRange) && InputMax.sle(MaxInRange)) {
- Known = InputKnown.trunc(BitWidth);
- } else if (InputMax.slt(MinInRange)) {
- Known.makeConstant(APInt::getSignedMinValue(BitWidth));
- } else if (InputMin.sgt(MaxInRange)) {
- Known.makeConstant(APInt::getSignedMaxValue(BitWidth));
- } else {
- Known.resetAll();
- if (InputKnown.isNegative()) {
- Known.makeNegative();
- Known.Zero = InputKnown.Zero.trunc(BitWidth);
- Known.Zero.clearSignBit();
- } else if (InputKnown.isNonNegative()) {
- Known.makeNonNegative();
- Known.One = InputKnown.One.trunc(BitWidth);
- }
+ // Pass through DemandedElts to the recursive call
+ KnownBits InputKnown =
+ computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
+ unsigned InputBits = InputKnown.getBitWidth();
+
+ APInt MinInRange = APInt::getSignedMinValue(BitWidth).sext(InputBits);
+ APInt MaxInRange = APInt::getSignedMaxValue(BitWidth).sext(InputBits);
+ APInt InputMin = InputKnown.getSignedMinValue();
+ APInt InputMax = InputKnown.getSignedMaxValue();
+
+ if (InputMin.sge(MinInRange) && InputMax.sle(MaxInRange)) {
+ Known = InputKnown.trunc(BitWidth);
+ } else if (InputMax.slt(MinInRange)) {
+ Known.makeConstant(APInt::getSignedMinValue(BitWidth));
+ } else if (InputMin.sgt(MaxInRange)) {
+ Known.makeConstant(APInt::getSignedMaxValue(BitWidth));
+ } else {
+ Known.resetAll();
+ if (InputKnown.isNegative()) {
+ Known.makeNegative();
+ Known.Zero = InputKnown.Zero.trunc(BitWidth);
+ Known.Zero.clearSignBit();
+ } else if (InputKnown.isNonNegative()) {
+ Known.makeNonNegative();
+ Known.One = InputKnown.One.trunc(BitWidth);
}
- break;
+ }
+ break;
}
case ISD::TRUNCATE_SSAT_U: {
// Signed -> Unsigned saturating truncation
- KnownBits InputKnown = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
+ KnownBits InputKnown =
+ computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
unsigned InputBits = InputKnown.getBitWidth();
APInt MaxInRange = APInt::getAllOnes(BitWidth).zext(InputBits);
@@ -4009,7 +4011,8 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
}
case ISD::TRUNCATE_USAT_U: {
// Unsigned -> Unsigned saturating truncation
- KnownBits InputKnown = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
+ KnownBits InputKnown =
+ computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
unsigned InputBits = InputKnown.getBitWidth();
APInt MaxInRange = APInt::getLowBitsSet(InputBits, BitWidth);
``````````
</details>
https://github.com/llvm/llvm-project/pull/168809
More information about the llvm-commits
mailing list