quinnp created this revision.
Herald added subscribers: shchenz, kbarton, nemanjai.
quinnp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch is in a series of patches to provide builtins for
compatibility with the XL compiler. This patch adds software divide
builtins with no checking. These builtins are each emitted as a fast
fdiv.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106150

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-swdiv_nochk.c

Index: clang/test/CodeGen/builtins-ppc-xlcompat-swdiv_nochk.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-swdiv_nochk.c
@@ -0,0 +1,113 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown \
+// RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown \
+// RUN:   -emit-llvm %s -o - -target-cpu pwr8 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix \
+// RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix \
+// RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
+
+extern double a;
+extern double b;
+extern double c;
+extern float d;
+extern float e;
+extern float f;
+
+// CHECK-LABEL: @test_swdiv_nochk(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[TMP0:%.*]] = load double, double* @a, align 8
+// CHECK-NEXT:    [[TMP1:%.*]] = load double, double* @b, align 8
+// CHECK-NEXT:    [[SWDIV_NOCHK:%.*]] = fdiv fast double [[TMP0]], [[TMP1]]
+// CHECK-NEXT:    ret double [[SWDIV_NOCHK]]
+//
+double test_swdiv_nochk() {
+  return __swdiv_nochk(a, b);
+}
+
+// CHECK-LABEL: @test_swdivs_nochk(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[TMP0:%.*]] = load float, float* @d, align 4
+// CHECK-NEXT:    [[TMP1:%.*]] = load float, float* @e, align 4
+// CHECK-NEXT:    [[SWDIV_NOCHK:%.*]] = fdiv fast float [[TMP0]], [[TMP1]]
+// CHECK-NEXT:    ret float [[SWDIV_NOCHK]]
+//
+float test_swdivs_nochk() {
+  return __swdivs_nochk(d, e);
+}
+
+// CHECK-LABEL: @test_flags_swdiv_nochk(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[TMP0:%.*]] = load double, double* @a, align 8
+// CHECK-NEXT:    [[TMP1:%.*]] = load double, double* @b, align 8
+// CHECK-NEXT:    [[SWDIV_NOCHK:%.*]] = fdiv fast double [[TMP0]], [[TMP1]]
+// CHECK-NEXT:    [[TMP2:%.*]] = load double, double* @c, align 8
+// CHECK-NEXT:    [[ADD:%.*]] = fadd double [[SWDIV_NOCHK]], [[TMP2]]
+// CHECK-NEXT:    ret double [[ADD]]
+//
+double test_flags_swdiv_nochk() {
+  return __swdiv_nochk(a, b) + c;
+}
+
+// CHECK-LABEL: @test_flags_swdivs_nochk(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[TMP0:%.*]] = load float, float* @d, align 4
+// CHECK-NEXT:    [[TMP1:%.*]] = load float, float* @e, align 4
+// CHECK-NEXT:    [[SWDIV_NOCHK:%.*]] = fdiv fast float [[TMP0]], [[TMP1]]
+// CHECK-NEXT:    [[TMP2:%.*]] = load float, float* @f, align 4
+// CHECK-NEXT:    [[ADD:%.*]] = fadd float [[SWDIV_NOCHK]], [[TMP2]]
+// CHECK-NEXT:    ret float [[ADD]]
+//
+float test_flags_swdivs_nochk() {
+  return __swdivs_nochk(d, e) + f;
+}
+
+// CHECK-LABEL: @test_builtin_ppc_swdiv_nochk(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[TMP0:%.*]] = load double, double* @a, align 8
+// CHECK-NEXT:    [[TMP1:%.*]] = load double, double* @b, align 8
+// CHECK-NEXT:    [[SWDIV_NOCHK:%.*]] = fdiv fast double [[TMP0]], [[TMP1]]
+// CHECK-NEXT:    ret double [[SWDIV_NOCHK]]
+//
+double test_builtin_ppc_swdiv_nochk() {
+  return __builtin_ppc_swdiv_nochk(a, b);
+}
+
+// CHECK-LABEL: @test_builtin_ppc_swdivs_nochk(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[TMP0:%.*]] = load float, float* @d, align 4
+// CHECK-NEXT:    [[TMP1:%.*]] = load float, float* @e, align 4
+// CHECK-NEXT:    [[SWDIV_NOCHK:%.*]] = fdiv fast float [[TMP0]], [[TMP1]]
+// CHECK-NEXT:    ret float [[SWDIV_NOCHK]]
+//
+float test_builtin_ppc_swdivs_nochk() {
+  return __builtin_ppc_swdivs_nochk(d, e);
+}
+
+// CHECK-LABEL: @test_flags_builtin_ppc_swdiv_nochk(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[TMP0:%.*]] = load double, double* @a, align 8
+// CHECK-NEXT:    [[TMP1:%.*]] = load double, double* @b, align 8
+// CHECK-NEXT:    [[SWDIV_NOCHK:%.*]] = fdiv fast double [[TMP0]], [[TMP1]]
+// CHECK-NEXT:    [[TMP2:%.*]] = load double, double* @c, align 8
+// CHECK-NEXT:    [[ADD:%.*]] = fadd double [[SWDIV_NOCHK]], [[TMP2]]
+// CHECK-NEXT:    ret double [[ADD]]
+//
+double test_flags_builtin_ppc_swdiv_nochk() {
+  return __builtin_ppc_swdiv_nochk(a, b) + c;
+}
+
+// CHECK-LABEL: @test_flags_builtin_ppc_swdivs_nochk(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[TMP0:%.*]] = load float, float* @d, align 4
+// CHECK-NEXT:    [[TMP1:%.*]] = load float, float* @e, align 4
+// CHECK-NEXT:    [[SWDIV_NOCHK:%.*]] = fdiv fast float [[TMP0]], [[TMP1]]
+// CHECK-NEXT:    [[TMP2:%.*]] = load float, float* @f, align 4
+// CHECK-NEXT:    [[ADD:%.*]] = fadd float [[SWDIV_NOCHK]], [[TMP2]]
+// CHECK-NEXT:    ret float [[ADD]]
+//
+float test_flags_builtin_ppc_swdivs_nochk() {
+  return __builtin_ppc_swdivs_nochk(d, e) + f;
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -15619,6 +15619,14 @@
     llvm::Type *ArgType = ArgValue->getType();
     Function *F = CGM.getIntrinsic(Intrinsic::ppc_popcntb, {ArgType, ArgType});
     return Builder.CreateCall(F, Ops, "popcntb");
+
+  case PPC::BI__builtin_ppc_swdiv_nochk:
+  case PPC::BI__builtin_ppc_swdivs_nochk: {
+    FastMathFlags FMF = Builder.getFastMathFlags();
+    Builder.getFastMathFlags().setFast();
+    Value *fdiv = Builder.CreateFDiv(Ops[0], Ops[1], "swdiv_nochk");
+    Builder.getFastMathFlags() &= (FMF);
+    return fdiv;
   }
   }
 }
Index: clang/lib/Basic/Targets/PPC.cpp
===================================================================
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -151,6 +151,8 @@
   Builder.defineMacro("__store2r", "__builtin_ppc_store2r");
   Builder.defineMacro("__store4r", "__builtin_ppc_store4r");
   Builder.defineMacro("__store8r", "__builtin_ppc_store8r");
+  Builder.defineMacro("__swdiv_nochk", "__builtin_ppc_swdiv_nochk");
+  Builder.defineMacro("__swdivs_nochk", "__builtin_ppc_swdivs_nochk");
 }
 
 /// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific
Index: clang/include/clang/Basic/BuiltinsPPC.def
===================================================================
--- clang/include/clang/Basic/BuiltinsPPC.def
+++ clang/include/clang/Basic/BuiltinsPPC.def
@@ -73,6 +73,8 @@
 BUILTIN(__builtin_ppc_fctiwz, "dd", "")
 BUILTIN(__builtin_ppc_fctudz, "dd", "")
 BUILTIN(__builtin_ppc_fctuwz, "dd", "")
+BUILTIN(__builtin_ppc_swdiv_nochk, "ddd", "")
+BUILTIN(__builtin_ppc_swdivs_nochk, "fff", "")
 // Compare
 BUILTIN(__builtin_ppc_cmpeqb, "LLiLLiLLi", "")
 BUILTIN(__builtin_ppc_cmprb, "iCIiii", "")
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to