[llvm] [SelectionDAG] SimplifySetCC - Improve shifted range checks with add offsets (PR #207955)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 10 02:39:34 PDT 2026
================
@@ -0,0 +1,184 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s --check-prefixes=X64
+; RUN: llc < %s -mtriple=i686-- | FileCheck %s --check-prefixes=X86
+
+; Test for https://github.com/llvm/llvm-project/issues/172674.
+
+define i1 @top_i16_range(i64 %x) {
+; X64-LABEL: top_i16_range:
+; X64: # %bb.0:
+; X64-NEXT: shrq $49, %rdi
+; X64-NEXT: addl $-5, %edi
+; X64-NEXT: cmpl $5, %edi
+; X64-NEXT: setb %al
+; X64-NEXT: retq
+;
+; X86-LABEL: top_i16_range:
+; X86: # %bb.0:
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: shrl $17, %eax
+; X86-NEXT: xorl %ecx, %ecx
+; X86-NEXT: addl $-5, %eax
+; X86-NEXT: adcl $-1, %ecx
+; X86-NEXT: cmpl $5, %eax
+; X86-NEXT: sbbl $0, %ecx
+; X86-NEXT: setb %al
+; X86-NEXT: retl
+ %offset = add i64 %x, -2814749767106560
+ %in.range = icmp ult i64 %offset, 2814749767106560
+ ret i1 %in.range
+}
+
+define i1 @top_i32_range(i64 %x) {
+; X64-LABEL: top_i32_range:
+; X64: # %bb.0:
+; X64-NEXT: shrq $32, %rdi
+; X64-NEXT: addq $-123, %rdi
+; X64-NEXT: cmpq $333, %rdi # imm = 0x14D
+; X64-NEXT: setb %al
+; X64-NEXT: retq
+;
+; X86-LABEL: top_i32_range:
+; X86: # %bb.0:
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: xorl %ecx, %ecx
+; X86-NEXT: addl $-123, %eax
+; X86-NEXT: adcl $-1, %ecx
+; X86-NEXT: cmpl $333, %eax # imm = 0x14D
+; X86-NEXT: sbbl $0, %ecx
+; X86-NEXT: setb %al
+; X86-NEXT: retl
+ %offset = add i64 %x, -528280977408
+ %in.range = icmp ult i64 %offset, 1430224109568
+ ret i1 %in.range
+}
+
+define i1 @top_i32_range_uge(i64 %x) {
----------------
RKSimon wrote:
Add `nounwind` to silence cfi noise - best to add to all tests for consistency tbh
```suggestion
define i1 @top_i32_range_uge(i64 %x) nounwind {
```
https://github.com/llvm/llvm-project/pull/207955
More information about the llvm-commits
mailing list