[llvm] 9cadc4e - [DAG] SelectionDAG::canCreateUndefOrPoison - add ISD::SCMP/UCMP handling + tests (#154127)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 19 02:06:17 PDT 2025
Author: Temperz87
Date: 2025-08-19T10:06:14+01:00
New Revision: 9cadc4e15362581e1b2a5b0216d180d181a08cfc
URL: https://github.com/llvm/llvm-project/commit/9cadc4e15362581e1b2a5b0216d180d181a08cfc
DIFF: https://github.com/llvm/llvm-project/commit/9cadc4e15362581e1b2a5b0216d180d181a08cfc.diff
LOG: [DAG] SelectionDAG::canCreateUndefOrPoison - add ISD::SCMP/UCMP handling + tests (#154127)
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
---------
Co-authored-by: Temperz87 <= temperz871 at gmail.com>
Co-authored-by: Simon Pilgrim <llvm-dev at redking.me.uk>
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/test/CodeGen/X86/freeze-binary.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index f2cb0c600910e..23102d3d8e407 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5664,8 +5664,10 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
case ISD::ABDS:
case ISD::SMIN:
case ISD::SMAX:
+ case ISD::SCMP:
case ISD::UMIN:
case ISD::UMAX:
+ case ISD::UCMP:
case ISD::AND:
case ISD::XOR:
case ISD::ROTL:
diff --git a/llvm/test/CodeGen/X86/freeze-binary.ll b/llvm/test/CodeGen/X86/freeze-binary.ll
index 962ffe47d0d51..e223765eb887b 100644
--- a/llvm/test/CodeGen/X86/freeze-binary.ll
+++ b/llvm/test/CodeGen/X86/freeze-binary.ll
@@ -924,6 +924,76 @@ 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 $2, %eax
+; X86-NEXT: cmpl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: setl %al
+; X86-NEXT: setg %cl
+; X86-NEXT: subb %al, %cl
+; X86-NEXT: movsbl %cl, %eax
+; X86-NEXT: negl %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: movl $2, %eax
+; X64-NEXT: cmpl %edi, %eax
+; X64-NEXT: setl %al
+; X64-NEXT: setg %cl
+; X64-NEXT: subb %al, %cl
+; X64-NEXT: movsbl %cl, %eax
+; X64-NEXT: negl %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 2, i32 %a0)
+ %y = freeze i32 %x
+ %z = call i32 @llvm.scmp.i32(i32 0, i32 %y)
+ ret i32 %z
+}
+
+define i32 @freeze_ucmp(i32 %a0) nounwind {
+; X86-LABEL: freeze_ucmp:
+; X86: # %bb.0:
+; X86-NEXT: movl $2, %eax
+; X86-NEXT: cmpl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: seta %al
+; X86-NEXT: sbbb $0, %al
+; X86-NEXT: movsbl %al, %eax
+; X86-NEXT: cmpl $2, %eax
+; X86-NEXT: setae %cl
+; X86-NEXT: cmpl $1, %eax
+; X86-NEXT: sbbb $0, %cl
+; X86-NEXT: movsbl %cl, %eax
+; X86-NEXT: retl
+;
+; X64-LABEL: freeze_ucmp:
+; X64: # %bb.0:
+; X64-NEXT: movl $2, %eax
+; X64-NEXT: cmpl %edi, %eax
+; X64-NEXT: seta %al
+; X64-NEXT: sbbb $0, %al
+; X64-NEXT: movsbl %al, %eax
+; X64-NEXT: cmpl $2, %eax
+; X64-NEXT: setae %cl
+; X64-NEXT: cmpl $1, %eax
+; X64-NEXT: sbbb $0, %cl
+; X64-NEXT: movsbl %cl, %eax
+; X64-NEXT: retq
+ %x = call i32 @llvm.ucmp.i32(i32 2, i32 %a0)
+ %y = freeze i32 %x
+ %z = call i32 @llvm.ucmp.i32(i32 %y, i32 1)
+ ret i32 %z
+}
+
define void @pr59676_frozen(ptr %dst, i32 %x.orig) {
; X86-LABEL: pr59676_frozen:
; X86: # %bb.0:
More information about the llvm-commits
mailing list