This revision was automatically updated to reflect the committed changes.
Closed by commit rG70f8dd4cf604: [CodeGen] Use IRBuilder::CreateFNeg for 
__builtin_conj (authored by craig.topper).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72012/new/

https://reviews.llvm.org/D72012

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/complex-builtins-2.c


Index: clang/test/CodeGen/complex-builtins-2.c
===================================================================
--- /dev/null
+++ 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);
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -1942,12 +1942,7 @@
     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:


Index: clang/test/CodeGen/complex-builtins-2.c
===================================================================
--- /dev/null
+++ 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);
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -1942,12 +1942,7 @@
     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:
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to