Skip to content

[X86][DAGCombiner] Fix assertion failure in combinei64TruncSrlAdd #128194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2025

Conversation

dtcxzyw
Copy link
Member

@dtcxzyw dtcxzyw commented Feb 21, 2025

Closes #128158.

@llvmbot
Copy link
Member

llvmbot commented Feb 21, 2025

@llvm/pr-subscribers-backend-x86

Author: Yingwei Zheng (dtcxzyw)

Changes

Closes #128158.


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

2 Files Affected:

  • (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+1-1)
  • (modified) llvm/test/CodeGen/X86/combine-i64-trunc-srl-add.ll (+28)
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 683c8c3bdf96d..57ce634607dc5 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -53713,7 +53713,7 @@ static SDValue combinei64TruncSrlAdd(SDValue N, EVT VT, SelectionDAG &DAG,
                                  m_ConstInt(SrlConst)))))
     return SDValue();
 
-  if (SrlConst.ule(31) || AddConst.lshr(SrlConst).shl(SrlConst) != AddConst)
+  if (SrlConst.ule(32) || AddConst.lshr(SrlConst).shl(SrlConst) != AddConst)
     return SDValue();
 
   SDValue AddLHSSrl =
diff --git a/llvm/test/CodeGen/X86/combine-i64-trunc-srl-add.ll b/llvm/test/CodeGen/X86/combine-i64-trunc-srl-add.ll
index 1ce1e7e1c2b9f..41e1a24b239a6 100644
--- a/llvm/test/CodeGen/X86/combine-i64-trunc-srl-add.ll
+++ b/llvm/test/CodeGen/X86/combine-i64-trunc-srl-add.ll
@@ -123,3 +123,31 @@ define i32 @test_trunc_add(i64 %x) {
   %conv = trunc i64 %shr to i32
   ret i32 %conv
 }
+
+; Make sure we don't crash on this test case.
+
+define i32 @pr128158(i64 %x) {
+; X64-LABEL: pr128158:
+; X64:       # %bb.0: # %entry
+; X64-NEXT:    movabsq $-4294967296, %rax # imm = 0xFFFFFFFF00000000
+; X64-NEXT:    addq %rdi, %rax
+; X64-NEXT:    shrq $32, %rax
+; X64-NEXT:    .p2align 4
+; X64-NEXT:  .LBB9_1: # %for.body
+; X64-NEXT:    # =>This Inner Loop Header: Depth=1
+; X64-NEXT:    cmpl $9, %eax
+; X64-NEXT:    jb .LBB9_1
+; X64-NEXT:  # %bb.2: # %exit
+; X64-NEXT:    xorl %eax, %eax
+; X64-NEXT:    retq
+entry:
+  br label %for.body
+
+for.body:
+  %add = add i64 %x, -4294967296
+  %cmp = icmp ult i64 %add, 38654705664
+  br i1 %cmp, label %for.body, label %exit
+
+exit:
+  ret i32 0
+}

@dtcxzyw dtcxzyw merged commit 3ec83f5 into llvm:main Feb 22, 2025
13 checks passed
@dtcxzyw dtcxzyw deleted the fix-pr128158 branch February 22, 2025 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SDAG] Assertion `NumBits >= MIN_INT_BITS && "bitwidth too small"' failed.
4 participants