[PATCH] D40299: [Complex] Don't use __div?c3 when building with fast-math.

Florian Hahn via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 28 12:22:44 PST 2017


fhahn added reviewers: arphaman, GorNishanov, hfinkel, fhahn.
fhahn added a comment.

Looks good to me, with some nits. However it seems that we do not use the fast math flags anywhere else in Clang codegen, so it would be good to clarify if it is OK to use it here.



================
Comment at: lib/CodeGen/CGExprComplex.cpp:768
+
     // If we have a complex operand on the RHS, we delegate to a libcall to
     // handle all of the complexities and minimize underflow/overflow cases.
----------------
Maybe we should update the comment that we do a similar simplification for floats with fast math enabled as for integers?


================
Comment at: lib/CodeGen/CGExprComplex.cpp:773
     // supported imaginary types in addition to complex types.
-    if (RHSi) {
+    if (RHSi && !FMF.isFast()) {
       BinOpInfo LibCallOp = Op;
----------------
Would the following structure be slightly easier to read?

if (RHSi) {
  if (FMF.isFast()) { simplify } else {libcall}
}


================
Comment at: lib/CodeGen/CGExprComplex.cpp:800
+      // (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd))
+      llvm::Value *AC = Builder.CreateFMul(LHSr, RHSr); // a*c
+      llvm::Value *BD = Builder.CreateFMul(LHSi, RHSi); // b*d
----------------
This is basically the same as the simplification for integers, unfortunate that we have to duplicate it (because of different instructions).


https://reviews.llvm.org/D40299





More information about the cfe-commits mailing list