[llvm] [DAG] SelectionDAG::canCreateUndefOrPoison - add ISD::SCMP/UCMP handling + tests (PR #154127)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 18 07:41:30 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
Author: None (Temperz87)
<details>
<summary>Changes</summary>
This pr aims to resolve #<!-- -->152144
In SelectionDAG::canCreateUndefOrPoison the ISD::SCMP/UCMP cases are added to always return false as they cannot generate poison or undef
The `freeze-binary.ll` file is now testing the SCMP/UCMP cases
---
Full diff: https://github.com/llvm/llvm-project/pull/154127.diff
2 Files Affected:
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+2)
- (modified) llvm/test/CodeGen/X86/freeze-binary.ll (+72-1)
``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 84282d8a1c37b..cbbf885115a59 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5748,6 +5748,8 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
case ISD::FMA:
case ISD::FMAD:
case ISD::FP_EXTEND:
+ case ISD::SCMP:
+ case ISD::UCMP:
// No poison except from flags (which is handled above)
return false;
diff --git a/llvm/test/CodeGen/X86/freeze-binary.ll b/llvm/test/CodeGen/X86/freeze-binary.ll
index 962ffe47d0d51..af5b26f6e2dd9 100644
--- a/llvm/test/CodeGen/X86/freeze-binary.ll
+++ b/llvm/test/CodeGen/X86/freeze-binary.ll
@@ -924,6 +924,77 @@ define i32 @freeze_usubo(i32 %a0, i32 %a1, i8 %a2, i8 %a3) nounwind {
ret i32 %r
}
+
+define i32 @freeze_scmp(i32 %a0) nounwind {
+; X86-LABEL: freeze_scmp:
+; X86: # %bb.0:
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: cmpl $2, %eax
+; X86-NEXT: setl %al
+; X86-NEXT: setg %cl
+; X86-NEXT: subb %al, %cl
+; X86-NEXT: movsbl %cl, %eax
+; X86-NEXT: cmpl $2, %eax
+; X86-NEXT: setl %al
+; X86-NEXT: setg %cl
+; X86-NEXT: subb %al, %cl
+; X86-NEXT: movsbl %cl, %eax
+; X86-NEXT: retl
+;
+; X64-LABEL: freeze_scmp:
+; X64: # %bb.0:
+; X64-NEXT: cmpl $2, %edi
+; X64-NEXT: setl %al
+; X64-NEXT: setg %cl
+; X64-NEXT: subb %al, %cl
+; X64-NEXT: movsbl %cl, %eax
+; X64-NEXT: cmpl $2, %eax
+; X64-NEXT: setl %al
+; X64-NEXT: setg %cl
+; X64-NEXT: subb %al, %cl
+; X64-NEXT: movsbl %cl, %eax
+; X64-NEXT: retq
+ %x = call i32 @llvm.scmp.i32(i32 %a0, i32 2)
+ %y = freeze i32 %x
+ %z = call i32 @llvm.scmp.i32(i32 %y, i32 2)
+ ret i32 %z
+}
+
+define i32 @freeze_ucmp(i32 %a0) nounwind {
+; X86-LABEL: freeze_ucmp:
+; X86: # %bb.0:
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: cmpl $3, %eax
+; X86-NEXT: setae %cl
+; X86-NEXT: cmpl $2, %eax
+; X86-NEXT: sbbb $0, %cl
+; X86-NEXT: movsbl %cl, %eax
+; X86-NEXT: cmpl $3, %eax
+; X86-NEXT: setae %cl
+; X86-NEXT: cmpl $2, %eax
+; X86-NEXT: sbbb $0, %cl
+; X86-NEXT: movsbl %cl, %eax
+; X86-NEXT: retl
+;
+; X64-LABEL: freeze_ucmp:
+; X64: # %bb.0:
+; X64-NEXT: cmpl $3, %edi
+; X64-NEXT: setae %al
+; X64-NEXT: cmpl $2, %edi
+; X64-NEXT: sbbb $0, %al
+; X64-NEXT: movsbl %al, %eax
+; X64-NEXT: cmpl $3, %eax
+; X64-NEXT: setae %cl
+; X64-NEXT: cmpl $2, %eax
+; X64-NEXT: sbbb $0, %cl
+; X64-NEXT: movsbl %cl, %eax
+; X64-NEXT: retq
+ %x = call i32 @llvm.ucmp.i32(i32 %a0, i32 2)
+ %y = freeze i32 %x
+ %z = call i32 @llvm.ucmp.i32(i32 %y, i32 2)
+ ret i32 %z
+}
+
define void @pr59676_frozen(ptr %dst, i32 %x.orig) {
; X86-LABEL: pr59676_frozen:
; X86: # %bb.0:
@@ -1036,4 +1107,4 @@ define void @pr59676_nsw(ptr %dst, i32 %x) {
%div = sdiv i32 %area, 42
store i32 %div, ptr %dst, align 4
ret void
-}
+}
\ No newline at end of file
``````````
</details>
https://github.com/llvm/llvm-project/pull/154127
More information about the llvm-commits
mailing list