[PATCH] D113107: Support of expression granularity for _Float16.

John McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 17 11:00:37 PDT 2022


rjmccall added inline comments.


================
Comment at: clang/lib/CodeGen/CGExprComplex.cpp:213
     TestAndClearIgnoreImag();
+    PromotionType = getPromotionType(E->getSubExpr()->getType());
+    if (!PromotionType.isNull())
----------------
Same problem


================
Comment at: clang/lib/CodeGen/CGExprComplex.cpp:288
+        const auto *BT = dyn_cast<BuiltinType>(Ty);
+        if (BT->getKind() == BuiltinType::Float16)
+          PromotedTy = CGF.getContext().FloatTy;
----------------
You can just use `isFloat16Type()` here.


================
Comment at: clang/lib/CodeGen/CGExprComplex.cpp:609
+  ComplexPairTy Op;
+  PromotionType = getPromotionType(E->getSubExpr()->getType());
+  if (!PromotionType.isNull())
----------------
This is overwriting the argument, so the code below doesn't understand whether it's supposed to be emitting a promoted result or not.  You can test this with something like:

```
cf16 = -cf16;
```

Here the context does not want a promoted result, but you will produce one anyway.

Because this operator does its own arithmetic, like the binary operators, it needs to follow the same basic logic:
- remember whether you're supposed to emit a promoted result
- if not, check whether you should do the arithmetic promoted anyway
- if you did the arithmetic promoted, but you're not supposed to emit a promoted result, unpromote the result


================
Comment at: clang/lib/CodeGen/CGExprScalar.cpp:626
     TestAndClearIgnoreResultAssign();
+    PromotionType = getPromotionType(E->getSubExpr()->getType());
+    if (!PromotionType.isNull())
----------------
Same problem


================
Comment at: clang/lib/CodeGen/CGExprScalar.cpp:2857
+  Value *Op;
+  PromotionType = getPromotionType(E->getSubExpr()->getType());
+  if (!PromotionType.isNull())
----------------
Same problem


================
Comment at: clang/lib/CodeGen/CGExprScalar.cpp:3073
   Expr *Op = E->getSubExpr();
+  PromotionType = getPromotionType(E->getSubExpr()->getType());
   if (Op->getType()->isAnyComplexType()) {
----------------
Same problem.  However, since `__real` and `__imag` don't really do arithmetic, we don't need to voluntarily promote here — you shoul emit the operand promoted if and only if we're given a promotion type.


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

https://reviews.llvm.org/D113107



More information about the llvm-commits mailing list