[PATCH] D102449: [WIP][Clang][OpenMP] Add the support for compare clause in atomic directive

Shilei Tian via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 1 12:48:37 PDT 2021


tianshilei1992 added a comment.

Another thing is how we deal with a corner case. Say the OpenMP code is written in the following way:

  #pragma omp atomic compare
    x = e < x ? e : x;

That's how OpenMP spec defines the atomic operation. `x` is always in "else statement" of a conditional statement.

Now we need to lower it to LLVM IR, which is `atomicrmw` operation. Based on the LLVM IR reference, it only supports the atomic operations that `x` is in the "then statement". For example: `x = x > e ? x : e`. See the `x` here is before `:`. In order to lower the OpenMP statement, we have to do a transformation. In order to swap `e` and `x`, we need to transform it to `x = e >= x : x : e`, a.k.a. `x = x <= e : x : e`. However, we don't have an atomic operation for `<=`. We only have `<`. So if `x != e`, the result is good.

The incorrectness happens if `x == e`. Recall at the OpenMP statement, when `x == e`, the result should be `x = x`. But if we look at our lowered LLVM IR, `x = x < e : x : e`, when `x == e`, it becomes `x = e`, which doesn't conform with OpenMP spec.

What should we do here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102449



More information about the cfe-commits mailing list