[llvm-bugs] [Bug 52216] New: [AArch64] improve codegen for -abs(x)

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Oct 19 07:08:09 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=52216

            Bug ID: 52216
           Summary: [AArch64] improve codegen for -abs(x)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: AArch64
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: arnaud.degrandmaison at arm.com,
                    llvm-bugs at lists.llvm.org, smithp352 at googlemail.com,
                    Ties.Stuij at arm.com

Splitting off from what was originally in bug 50991 (but that was fixed for x86
only):

define i32 @nabs32(i32 %0) {
  %2 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
  %3 = sub nsw i32 0, %2
  ret i32 %3
}

define i64 @nabs64(i64 %0) {
  %2 = tail call i64 @llvm.abs.i64(i64 %0, i1 true) #3
  %3 = sub nsw i64 0, %2
  ret i64 %3
}

declare i32 @llvm.abs.i32(i32, i1 immarg)
declare i64 @llvm.abs.i64(i64, i1 immarg)

----------------------------------------------------------------------------

% llc -o - nabs.ll -mtriple=aarch64
nabs32:                                 // @nabs32
        cmp     w0, #0
        cneg    w8, w0, mi
        neg     w0, w8
        ret

nabs64:                                 // @nabs64
        cmp     x0, #0
        cneg    x8, x0, mi
        neg     x0, x8
        ret

----------------------------------------------------------------------------

gcc does better on these:
https://godbolt.org/z/GbYha3Kso
...but note that i8 and possibly i16 are better as-is with clang.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20211019/a3bd7eb4/attachment.html>


More information about the llvm-bugs mailing list