[DAG] SimplifyDemandedBits - if we're only demanding the signbit, a SMIN/SMAX node can be simplified to a OR/AND node respectively.

Alive2: https://alive2.llvm.org/ce/z/MehvFB
This commit is contained in:
Simon Pilgrim committed 2023-08-18 11:35:34 +01:00
1 parent 4772c66cfb
commit 54d663d589
3 files changed
+20 -10

No files matched your search

@@ -1688,6 +1688,22 @@ bool TargetLowering::SimplifyDemandedBits(
Known.Zero.setBitsFrom(1);
break;
}
case ISD::SMIN: {
SDValue Op0 = Op.getOperand(0);
SDValue Op1 = Op.getOperand(1);
// If we're only wanting the signbit, then we can simplify to OR node.
if (OriginalDemandedBits.isSignMask())
return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::OR, dl, VT, Op0, Op1));
break;
}
case ISD::SMAX: {
SDValue Op0 = Op.getOperand(0);
SDValue Op1 = Op.getOperand(1);
// If we're only wanting the signbit, then we can simplify to AND node.
if (OriginalDemandedBits.isSignMask())
return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::AND, dl, VT, Op0, Op1));
break;
}
case ISD::SHL: {
SDValue Op0 = Op.getOperand(0);
SDValue Op1 = Op.getOperand(1);
+2 -5
View File
@@ -692,9 +692,7 @@ define i64 @test_signbits_i64(i64 %a, i64 %b) nounwind {
; X86-LABEL: test_signbits_i64:
; X86: # %bb.0:
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
; X86-NEXT: cmpl %eax, %ecx
; X86-NEXT: cmovgl %ecx, %eax
; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
; X86-NEXT: movl %eax, %edx
; X86-NEXT: sarl $31, %edx
; X86-NEXT: retl
@@ -709,8 +707,7 @@ define i128 @test_signbits_i128(i128 %a, i128 %b) nounwind {
; X64: # %bb.0:
; X64-NEXT: movq %rcx, %rax
; X64-NEXT: sarq $28, %rax
; X64-NEXT: cmpq %rax, %rsi
; X64-NEXT: cmovgq %rsi, %rax
; X64-NEXT: andq %rsi, %rax
; X64-NEXT: movq %rax, %rdx
; X64-NEXT: sarq $63, %rdx
; X64-NEXT: retq
+2 -5
View File
@@ -693,9 +693,7 @@ define i64 @test_signbits_i64(i64 %a, i64 %b) nounwind {
; X86-LABEL: test_signbits_i64:
; X86: # %bb.0:
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
; X86-NEXT: cmpl %eax, %ecx
; X86-NEXT: cmovll %ecx, %eax
; X86-NEXT: orl {{[0-9]+}}(%esp), %eax
; X86-NEXT: movl %eax, %edx
; X86-NEXT: sarl $31, %edx
; X86-NEXT: retl
@@ -710,8 +708,7 @@ define i128 @test_signbits_i128(i128 %a, i128 %b) nounwind {
; X64: # %bb.0:
; X64-NEXT: movq %rcx, %rax
; X64-NEXT: sarq $28, %rax
; X64-NEXT: cmpq %rax, %rsi
; X64-NEXT: cmovlq %rsi, %rax
; X64-NEXT: orq %rsi, %rax
; X64-NEXT: movq %rax, %rdx
; X64-NEXT: sarq $63, %rdx
; X64-NEXT: retq