Author: Craig Topper Date: 2019-12-30T13:25:23-08:00 New Revision: 70f8dd4cf604b2be3488895ef0d261154c1c1124
URL: https://github.com/llvm/llvm-project/commit/70f8dd4cf604b2be3488895ef0d261154c1c1124 DIFF: https://github.com/llvm/llvm-project/commit/70f8dd4cf604b2be3488895ef0d261154c1c1124.diff LOG: [CodeGen] Use IRBuilder::CreateFNeg for __builtin_conj This replaces the fsub -0.0 idiom with an fneg instruction. We didn't see to have a test that showed the current codegen. Just some tests for constant folding and a test that was only checking the declare lines for libcalls. The latter just checked that we did not have a declare for @conj when using __builtin_conj. Differential Revision: https://reviews.llvm.org/D72012 Added: clang/test/CodeGen/complex-builtins-2.c Modified: clang/lib/CodeGen/CGBuiltin.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 17b8cab71294..fe0607bbd027 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -1942,12 +1942,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0)); Value *Real = ComplexVal.first; Value *Imag = ComplexVal.second; - Value *Zero = - Imag->getType()->isFPOrFPVectorTy() - ? llvm::ConstantFP::getZeroValueForNegation(Imag->getType()) - : llvm::Constant::getNullValue(Imag->getType()); - - Imag = Builder.CreateFSub(Zero, Imag, "sub"); + Imag = Builder.CreateFNeg(Imag, "neg"); return RValue::getComplex(std::make_pair(Real, Imag)); } case Builtin::BI__builtin_creal: diff --git a/clang/test/CodeGen/complex-builtins-2.c b/clang/test/CodeGen/complex-builtins-2.c new file mode 100644 index 000000000000..d112637a6cb5 --- /dev/null +++ b/clang/test/CodeGen/complex-builtins-2.c @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -w -S -o - -emit-llvm %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -w -S -o - -emit-llvm -fmath-errno %s | FileCheck %s + +float _Complex test__builtin_conjf(float _Complex x) { +// CHECK-LABEL: @test__builtin_conjf( +// CHECK: fneg float %x.imag + return __builtin_conjf(x); +} + +double _Complex test__builtin_conj(double _Complex x) { +// CHECK-LABEL: @test__builtin_conj( +// CHECK: fneg double %x.imag + return __builtin_conj(x); +} + +long double _Complex test__builtin_conjl(long double _Complex x) { +// CHECK-LABEL: @test__builtin_conjl( +// CHECK: fneg x86_fp80 %x.imag + return __builtin_conjl(x); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits