quinnp updated this revision to Diff 359093. quinnp marked an inline comment as done. quinnp added a comment.
Adressing review comment. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D105984/new/ https://reviews.llvm.org/D105984 Files: clang/lib/CodeGen/CGBuiltin.cpp clang/test/CodeGen/builtins-ppc-fastmath.c
Index: clang/test/CodeGen/builtins-ppc-fastmath.c =================================================================== --- /dev/null +++ clang/test/CodeGen/builtins-ppc-fastmath.c @@ -0,0 +1,74 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// 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 vector float a; +extern vector float b; +extern vector float c; +extern vector double d; +extern vector double e; +extern vector double f; + +// CHECK-LABEL: @test_flags_recipdivf( +// CHECK-NEXT: entry: +// CHECK-NEXT: [[TMP0:%.*]] = load <4 x float>, <4 x float>* @a, align 16 +// CHECK-NEXT: [[TMP1:%.*]] = load <4 x float>, <4 x float>* @b, align 16 +// CHECK-NEXT: [[TMP2:%.*]] = load <4 x float>, <4 x float>* @a, align 16 +// CHECK-NEXT: [[TMP3:%.*]] = load <4 x float>, <4 x float>* @b, align 16 +// CHECK-NEXT: [[RECIPDIV:%.*]] = fdiv fast <4 x float> [[TMP2]], [[TMP3]] +// CHECK-NEXT: [[TMP4:%.*]] = load <4 x float>, <4 x float>* @c, align 16 +// CHECK-NEXT: [[ADD:%.*]] = fadd <4 x float> [[RECIPDIV]], [[TMP4]] +// CHECK-NEXT: ret <4 x float> [[ADD]] +// +vector float test_flags_recipdivf() { + return __builtin_ppc_recipdivf(a, b) + c; +} + +// CHECK-LABEL: @test_flags_recipdivd( +// CHECK-NEXT: entry: +// CHECK-NEXT: [[TMP0:%.*]] = load <2 x double>, <2 x double>* @d, align 16 +// CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, <2 x double>* @e, align 16 +// CHECK-NEXT: [[TMP2:%.*]] = load <2 x double>, <2 x double>* @d, align 16 +// CHECK-NEXT: [[TMP3:%.*]] = load <2 x double>, <2 x double>* @e, align 16 +// CHECK-NEXT: [[RECIPDIV:%.*]] = fdiv fast <2 x double> [[TMP2]], [[TMP3]] +// CHECK-NEXT: [[TMP4:%.*]] = load <2 x double>, <2 x double>* @f, align 16 +// CHECK-NEXT: [[ADD:%.*]] = fadd <2 x double> [[RECIPDIV]], [[TMP4]] +// CHECK-NEXT: ret <2 x double> [[ADD]] +// +vector double test_flags_recipdivd() { + return __builtin_ppc_recipdivd(d, e) + f; +} + +// CHECK-LABEL: @test_flags_rsqrtf( +// CHECK-NEXT: entry: +// CHECK-NEXT: [[TMP0:%.*]] = load <4 x float>, <4 x float>* @a, align 16 +// CHECK-NEXT: [[TMP1:%.*]] = load <4 x float>, <4 x float>* @a, align 16 +// CHECK-NEXT: [[TMP2:%.*]] = call fast <4 x float> @llvm.sqrt.v4f32(<4 x float> [[TMP1]]) +// CHECK-NEXT: [[RSQRT:%.*]] = fdiv fast <4 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, [[TMP2]] +// CHECK-NEXT: [[TMP3:%.*]] = load <4 x float>, <4 x float>* @b, align 16 +// CHECK-NEXT: [[ADD:%.*]] = fadd <4 x float> [[RSQRT]], [[TMP3]] +// CHECK-NEXT: ret <4 x float> [[ADD]] +// +vector float test_flags_rsqrtf() { + return __builtin_ppc_rsqrtf(a) + b; +} + +// CHECK-LABEL: @test_flags_rsqrtd( +// CHECK-NEXT: entry: +// CHECK-NEXT: [[TMP0:%.*]] = load <2 x double>, <2 x double>* @d, align 16 +// CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, <2 x double>* @d, align 16 +// CHECK-NEXT: [[TMP2:%.*]] = call fast <2 x double> @llvm.sqrt.v2f64(<2 x double> [[TMP1]]) +// CHECK-NEXT: [[RSQRT:%.*]] = fdiv fast <2 x double> <double 1.000000e+00, double 1.000000e+00>, [[TMP2]] +// CHECK-NEXT: [[TMP3:%.*]] = load <2 x double>, <2 x double>* @e, align 16 +// CHECK-NEXT: [[ADD:%.*]] = fadd <2 x double> [[RSQRT]], [[TMP3]] +// CHECK-NEXT: ret <2 x double> [[ADD]] +// +vector double test_flags_rsqrtd() { + return __builtin_ppc_rsqrtd(d) + e; +} Index: clang/lib/CodeGen/CGBuiltin.cpp =================================================================== --- clang/lib/CodeGen/CGBuiltin.cpp +++ clang/lib/CodeGen/CGBuiltin.cpp @@ -15128,6 +15128,7 @@ case PPC::BI__builtin_ppc_recipdivd: case PPC::BI__builtin_ppc_rsqrtf: case PPC::BI__builtin_ppc_rsqrtd: { + FastMathFlags FMF = Builder.getFastMathFlags(); Builder.getFastMathFlags().setFast(); llvm::Type *ResultType = ConvertType(E->getType()); Value *X = EmitScalarExpr(E->getArg(0)); @@ -15135,11 +15136,15 @@ if (BuiltinID == PPC::BI__builtin_ppc_recipdivf || BuiltinID == PPC::BI__builtin_ppc_recipdivd) { Value *Y = EmitScalarExpr(E->getArg(1)); - return Builder.CreateFDiv(X, Y, "recipdiv"); + Value *fdiv = Builder.CreateFDiv(X, Y, "recipdiv"); + Builder.getFastMathFlags() &= (FMF); + return fdiv; } auto *One = ConstantFP::get(ResultType, 1.0); llvm::Function *F = CGM.getIntrinsic(Intrinsic::sqrt, ResultType); - return Builder.CreateFDiv(One, Builder.CreateCall(F, X), "rsqrt"); + Value *fdiv = Builder.CreateFDiv(One, Builder.CreateCall(F, X), "rsqrt"); + Builder.getFastMathFlags() &= (FMF); + return fdiv; } // FMA variations
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits