[PATCH] D120290: [Clang][OpenMP] Add the codegen support for `atomic compare capture`

Shilei Tian via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 5 05:42:44 PDT 2022


tianshilei1992 added inline comments.


================
Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:6168
   llvm::Value *EVal = CGF.EmitScalarExpr(E);
+  if (auto CI = dyn_cast<llvm::ConstantInt>(EVal))
+    EVal = CGF.Builder.CreateIntCast(
----------------
ABataev wrote:
> 1. `auto *CI`
> 2. What if this is not a constant, but just a value with int type? Is this possible?
> What if this is not a constant, but just a value with int type? Is this possible?
I'm thinking of a similar case.
```
void foo() {
  int e, d;
  char x, v;
  if (x == e)
    x = d;
}
```
In this case, there are two casts:
1. In expression `x == e`, cast `x` to `int`.
2. In expression `x = d`, cast `d` to `char`.
We cannot ignore both of them. For the 2nd, no question. For the expression `x == e`, the problem is in `e` instead of `x`. `e` here is always `int`, further causing issue in codegen.

I'm thinking for those lvalues, we can only set them where they are used as lvalues in case any type lifting. For those rvalues, if their types are not same as `x`, but compatible with `x`, we have to insert cast, including truncate, before feed them into codegen. Does it sound good?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120290



More information about the cfe-commits mailing list