Issue 233893
Summary [OpenMP] Context selector tie-break only compares each candidate with the current best
Labels flang:openmp, clang:openmp
Assignees chichunchen
Reporter chichunchen
    When several context selectors tie for the highest score, a selector
that is a strict subset of another tied selector loses, and otherwise
the first one wins. `getBestVariantMatchForContext` applies this by
comparing each candidate only with the current best. That comparison
isn't transitive, so a selector that should lose can still be picked:

```c
void f(void) {
#pragma omp metadirective \
    when(user={condition(1)}, implementation={vendor(score(4): llvm)}: taskyield) \
 when(device={kind(cpu)}, implementation={vendor(score(3): llvm)}: taskwait) \
    when(user={condition(1)}, device={kind(host)}, implementation={vendor(score(3): llvm)}: barrier)
}
```

All three selectors match on the host and score 5. The first is a strict
subset of the third. Neither of the first two is a subset of the other,
and the same holds for the second and third. So the first should drop
out, the second and third tie, and clause order should select TASKWAIT.
`clang -fopenmp -S -emit-llvm` emits `__kmpc_barrier` instead.

The scan keeps the first selector over the second, since neither is a
subset of the other. It then replaces the first with the third, since the
first is a strict subset of it, and never compares the third with the
second.

Flang gives the same result:

```fortran
subroutine f()
  !$omp metadirective &
  !$omp& when(user={condition(.true.)}, implementation={vendor(score(4): llvm)}: taskyield) &
  !$omp& when(device={kind(cpu)}, implementation={vendor(score(3): llvm)}: taskwait) &
  !$omp& when(user={condition(.true.)}, device={kind(host)}, implementation={vendor(score(3): llvm)}: barrier)
end subroutine
```

`flang -fopenmp -S -emit-llvm` also emits `__kmpc_barrier`. Clang's
declare variant selection uses the same function.

Found while reviewing #233493, where the same shape with runtime
conditions, `condition(a)`, `condition(b)` and `condition(a)`, runs into
this once different runtime conditions are no longer treated as subsets
of each other.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to