[llvm] [DAG] Reducing instructions by better legalization handling of AVGFLOORU for illegal data types (PR #99913)

Julius Alexandre via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 23 10:08:01 PDT 2024


================
@@ -0,0 +1,159 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc -mtriple=x86_64 < %s | FileCheck %s
+
+define i128 @avgflooru_i128(i128 %x, i128 %y) {
+; CHECK-LABEL: avgflooru_i128:
+; CHECK:       # %bb.0: # %start
+; CHECK-NEXT:    movq %rdi, %rax
+; CHECK-NEXT:    addq %rdx, %rax
+; CHECK-NEXT:    adcq %rcx, %rsi
+; CHECK-NEXT:    setb %cl
+; CHECK-NEXT:    setb %dl
+; CHECK-NEXT:    movzbl %dl, %edi
+; CHECK-NEXT:    shlq $63, %rdi
+; CHECK-NEXT:    xorl %edx, %edx
+; CHECK-NEXT:    testb %cl, %cl
+; CHECK-NEXT:    cmovneq %rdi, %rdx
+; CHECK-NEXT:    shrdq $1, %rsi, %rax
+; CHECK-NEXT:    shrq %rsi
+; CHECK-NEXT:    orq %rsi, %rdx
+; CHECK-NEXT:    retq
+start:
+  %xor = xor i128 %y, %x
+  %lshr = lshr i128 %xor, 1
+  %and = and i128 %y, %x
+  %add = add i128 %lshr, %and
+  ret i128 %add
+}
+
+declare void @use(i8)
+
+define i128 @avgflooru_i128_multi_use(i128 %x, i128 %y) nounwind {
+; CHECK-LABEL: avgflooru_i128_multi_use:
+; CHECK:       # %bb.0: # %start
+; CHECK-NEXT:    pushq %r15
+; CHECK-NEXT:    pushq %r14
+; CHECK-NEXT:    pushq %r13
+; CHECK-NEXT:    pushq %r12
+; CHECK-NEXT:    pushq %rbx
+; CHECK-NEXT:    movq %rsi, %r15
+; CHECK-NEXT:    movq %rdi, %r12
+; CHECK-NEXT:    movq %rdi, %rbx
+; CHECK-NEXT:    addq %rdx, %rbx
+; CHECK-NEXT:    movq %rsi, %r14
+; CHECK-NEXT:    adcq %rcx, %r14
+; CHECK-NEXT:    setb %al
+; CHECK-NEXT:    setb %sil
+; CHECK-NEXT:    movzbl %sil, %esi
+; CHECK-NEXT:    shlq $63, %rsi
+; CHECK-NEXT:    xorl %r13d, %r13d
+; CHECK-NEXT:    testb %al, %al
+; CHECK-NEXT:    cmovneq %rsi, %r13
+; CHECK-NEXT:    xorq %rcx, %r15
+; CHECK-NEXT:    xorq %rdx, %r12
+; CHECK-NEXT:    movq %r12, %rdi
+; CHECK-NEXT:    movq %r15, %rsi
+; CHECK-NEXT:    callq use at PLT
+; CHECK-NEXT:    shrdq $1, %r15, %r12
+; CHECK-NEXT:    shrq %r15
+; CHECK-NEXT:    movq %r12, %rdi
+; CHECK-NEXT:    movq %r15, %rsi
+; CHECK-NEXT:    callq use at PLT
+; CHECK-NEXT:    shrdq $1, %r14, %rbx
+; CHECK-NEXT:    shrq %r14
+; CHECK-NEXT:    orq %r13, %r14
+; CHECK-NEXT:    movq %rbx, %rax
+; CHECK-NEXT:    movq %r14, %rdx
+; CHECK-NEXT:    popq %rbx
+; CHECK-NEXT:    popq %r12
+; CHECK-NEXT:    popq %r13
+; CHECK-NEXT:    popq %r14
+; CHECK-NEXT:    popq %r15
+; CHECK-NEXT:    retq
+start:
+  %xor = xor i128 %y, %x
+  call void @use(i128 %xor)
+  %lshr = lshr i128 %xor, 1
+  call void @use(i128 %lshr)
+  %and = and i128 %y, %x
+  %add = add i128 %lshr, %and
+  ret i128 %add
+}
+
+define i128 @avgflooru_i128_negative(i128 %x, i128 %y) {
----------------
medievalghoul wrote:

Done, I'll make sure to do that from now on

https://github.com/llvm/llvm-project/pull/99913


More information about the llvm-commits mailing list