[PATCH] D123372: [PowerPC] add XLC compat builtin __abs

ChenZheng via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 8 02:37:44 PDT 2022

shchenz created this revision.
shchenz added reviewers: stefanp, nemanjai, jsji, qiucf, PowerPC.
Herald added a subscriber: kbarton.
Herald added a project: All.
shchenz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is ´╗┐supplement of D104386 <https://reviews.llvm.org/D104386>, we add one more XLC compat builtin __abs.

  rG LLVM Github Monorepo



Index: clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-macros.c
--- clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-macros.c
+++ clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-macros.c
@@ -12,6 +12,19 @@
 // Required for size_t. Usually found in stddef.h.
 typedef __SIZE_TYPE__ size_t;
+// BOTH-LABEL: @testabs(
+// BOTH-NEXT:  entry:
+// BOTH-NEXT:    [[A_ADDR:%.*]] = alloca i32, align 4
+// BOTH-NEXT:    store i32 [[A:%.*]], i32* [[A_ADDR]], align 4
+// BOTH-NEXT:    [[TMP0:%.*]] = load i32, i32* [[A_ADDR]], align 4
+// BOTH-NEXT:    [[NEG:%.*]] = sub nsw i32 0, [[TMP0]]
+// BOTH-NEXT:    [[ABSCOND:%.*]] = icmp slt i32 [[TMP0]], 0
+// BOTH-NEXT:    [[ABS:%.*]] = select i1 [[ABSCOND]], i32 [[NEG]], i32 [[TMP0]]
+// BOTH-NEXT:    ret i32 [[ABS]]
+signed int testabs(signed int a) {
+  return __abs(a);
 // 64BIT-LABEL: @testlabs(
 // 64BIT-NEXT:  entry:
 // 64BIT-NEXT:    [[A_ADDR:%.*]] = alloca i64, align 8
Index: clang/lib/Basic/Targets/PPC.cpp
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -206,6 +206,7 @@
   Builder.defineMacro("__dcbf", "__builtin_dcbf");
   Builder.defineMacro("__fmadd", "__builtin_fma");
   Builder.defineMacro("__fmadds", "__builtin_fmaf");
+  Builder.defineMacro("__abs", "__builtin_abs");
   Builder.defineMacro("__labs", "__builtin_labs");
   Builder.defineMacro("__llabs", "__builtin_llabs");
   Builder.defineMacro("__popcnt4", "__builtin_popcount");

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123372.421465.patch
Type: text/x-patch
Size: 1570 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220408/1b487ad9/attachment.bin>

More information about the cfe-commits mailing list