Skip to content

[AArch64] improve codegen for -abs(x) #51558

@rotateright

Description

@rotateright
Bugzilla Link 52216
Version trunk
OS All
CC @Arnaud-de-Grandmaison-ARM,@DMG862,@GabrielRavier,@smithp35

Extended Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions