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

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 23 14:08:25 PDT 2022


rjmccall added inline comments.


================
Comment at: clang/lib/CodeGen/CGExprScalar.cpp:3075
+                        ConvertType(DstType), ScalarConversionOpts());
+}
+
----------------
...I wrote out what this function should look like, and Phabricator just threw it away.  Let me try to write it out again.

This function is performing normal, unpromoted emission and then promoting the result.  That is not correct; it should be recognizing the expressions that support promoted emission and then requested promoted emission for them.  It should only fall back on unpromoted emission for the expressions that don't support promoted emission.  This necessarily means that you'll need to do a reduced version of the expression switch-out that the normal emitter does, like so:

```
Value *ScalarExprEmitter::EmitPromoted(const Expr *E, QualType PromotionType) {
  if (auto BO = dyn_cast<BinaryOperator>(E)) {
    switch (BO->getOpcode()) {
#define HANDLE_BINOP(OP) \
    case BO_##OP: return EmitBin##OP(EmitBinOps(E, PromotionType));
    HANDLE_BINOP(Add)
    HANDLE_BINOP(Sub)
    HANDLE_BINOP(Mul)
    HANDLE_BINOP(Div)
#undef HANDLE_BINOP
    default: break;
    }
  } else if (...) { // <- recognize other expressions that support promoted emission here
  }

  // fallback path
  auto result = Visit(E);
  if (result) result = CGF.Builder.CreateFPExt(result, ConvertType(E->getType()));
  return result;
}
```


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

https://reviews.llvm.org/D113107



More information about the cfe-commits mailing list