[PATCH] D126602: [Clang][OpenMP] Replace IgnoreImpCasts with IgnoreImplicitAsWritten in atomic compare

Shilei Tian via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 2 09:50:12 PDT 2022


tianshilei1992 added a comment.

I will refine some logics to set `X`, `E`, etc. to avoid more `IgnoreImpCasts`. However, I don't know how to deal with type promotion in the condition statement. Here we consider the following case:

  if (x == e) { x = d; }

`x` and `d` can be set easily w/o need of `IgnoreImpCasts`. When it comes to `e`, things become complicated. There are basically three cases:

1. `x` and `e` are not promoted. That is the case when `x` and `e` are of same type, and they are both at least `int`. In this case, we don't need `IgnoreImpCasts` here. If they are of the same with shorter representation, such as `int16_t`, they will all be promoted, which will be mentioned later.
2. `x` is not promoted, but `e` is promoted. That is the case when `x` has higher ranking than `e`. In this case, we should not use `IgnoreImpCasts`.
3. Both `x` and `e` are promoted. This case is very common, and it can be further divided into following cases:
  - `x` and `e` of the same type with lower ranking. For example, when `x` and `e` are both `short`, they will be promoted to `int`. In this case, we want `IgnoreImpCasts`.
  - `x` and `e` are of different types, but they can be implicitly converted. For example, `x` is `int`, while `e` is `short`. In this case, we don't want `IgnoreImpCasts` because `e` is implicitly promoted to `int`, which is exactly what we want.

I'm thinking we may want to avoid using `IgnoreImpCasts` and later create cast if necessary. However, that may cause some unnecessary casts, at least in LLVM IR, such as the following case:

  %1 = load i8 *%e
  %2 = cast to i32 %1
  %3 = cast to i8 %2
  cmpxchg i8 * %x, i8 %3

I'm not sure eventually `%2` and `%3` will be optimized out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126602



More information about the cfe-commits mailing list