Skip to content

[DAGCombiner] Restrict combineOrOfSetCCToUSUBOCarry to ZeroOrOneBooleanContent. - #224759

Merged
topperc merged 2 commits into
llvm:mainfrom
topperc:pr/booleancontents
Sep 20, 2026
Merged

topperc merged 2 commits into
llvm:mainfrom
topperc:pr/booleancontents

Conversation

@topperc

@topperc topperc commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

We need to ensure the carry in matches boolean contents. We are checking MaskedValueIsZero which is only valid for ZeroOrOneBooleanContent.

We could check ComputeNumSignBits for ZeroOrNegativeOneBooleanContent, but no in tree target supports USUBO_CARRY and ZeroOrNegativeOneBooleanContent.

This was an oversight in #223396 due to incorrect documentation for USUBO_CARRY. I will fix that in a separate patch.

…anContent.

We need to ensure the carry in matches boolean contents. We are
checking MaskedValueIsZero which is only valid for ZeroOrOneBooleanContent.

We could check ComputeNumSignBits for ZeroOrNegativeOneBooleanContent,
but no in tree target supports USUBO_CARRY and ZeroOrNegativeOneBooleanContent.
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-llvm-selectiondag

Author: Craig Topper (topperc)

Changes

We need to ensure the carry in matches boolean contents. We are checking MaskedValueIsZero which is only valid for ZeroOrOneBooleanContent.

We could check ComputeNumSignBits for ZeroOrNegativeOneBooleanContent, but no in tree target supports USUBO_CARRY and ZeroOrNegativeOneBooleanContent.

This was an oversight in #223396 due to incorrect documentation for USUBO_CARRY. I will fix that in a separate patch.


Full diff: https://github.com/llvm/llvm-project/pull/224759.diff

1 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+5-3)
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index a9485e336837e..59d6cc7652510 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -3972,9 +3972,11 @@ static SDValue combineOrOfSetCCToUSUBOCarry(SDNode *N, SelectionDAG &DAG,
                                                     *DAG.getContext(), IntVT)))
     return SDValue();
 
-  // USUBO_CARRY's carry-in must be 0 or 1, which the matched pattern does not
-  // guarantee.
-  if (!DAG.MaskedValueIsZero(
+  // USUBO_CARRY's carry-in must match boolean contents, which the matched
+  // pattern does not guarantee.
+  if (TLI.getBooleanContents(IntVT) !=
+          TargetLowering::ZeroOrOneBooleanContent ||
+      !DAG.MaskedValueIsZero(
           CarryIn,
           APInt::getBitsSetFrom(CarryIn.getScalarValueSizeInBits(), 1)))
     return SDValue();

// guarantee.
if (!DAG.MaskedValueIsZero(
// USUBO_CARRY's carry-in must match boolean contents, which the matched
// pattern does not guarantee.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May add additional TODO to extent this to all bool constants variants.

@RKSimon RKSimon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@topperc
topperc merged commit 51d2905 into llvm:main Sep 20, 2026
11 checks passed
@topperc
topperc deleted the pr/booleancontents branch September 20, 2026 17:13
@topperc topperc added this to the LLVM 23.x Release milestone Sep 21, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in LLVM Release Status Sep 21, 2026
@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in LLVM Release Status Sep 21, 2026
@llvmbot

llvmbot commented Sep 21, 2026

Copy link
Copy Markdown
Member

Failed to cherry-pick: 51d2905

https://github.com/llvm/llvm-project/actions/runs/35632869368

Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request

tru pushed a commit that referenced this pull request Sep 23, 2026
…anContent. (#224759)

We need to ensure the carry in matches boolean contents. We are checking
MaskedValueIsZero which is only valid for ZeroOrOneBooleanContent.

We could check ComputeNumSignBits for ZeroOrNegativeOneBooleanContent,
but no in tree target supports USUBO_CARRY and
ZeroOrNegativeOneBooleanContent.

This was an oversight in #223396 due to incorrect documentation for
USUBO_CARRY. I will fix that in a separate patch.

(cherry picked from commit 51d2905)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

4 participants