diff --git a/clang/include/clang/Basic/BuiltinsPPC.def b/clang/include/clang/Basic/BuiltinsPPC.def --- a/clang/include/clang/Basic/BuiltinsPPC.def +++ b/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", "") diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp --- a/clang/lib/Basic/Targets/PPC.cpp +++ b/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 diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -15620,6 +15620,15 @@ 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; + } } } diff --git a/clang/test/CodeGen/builtins-ppc-xlcompat-swdiv_nochk.c b/clang/test/CodeGen/builtins-ppc-xlcompat-swdiv_nochk.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/builtins-ppc-xlcompat-swdiv_nochk.c @@ -0,0 +1,100 @@ +// 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 powerpc64-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: [[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: [[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: [[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: [[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: [[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: [[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: [[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: [[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; +}