[clang] [flang] [llvm] [flang][OpenMP] Don't treat different runtime conditions as subsets (PR #233493)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 12 23:00:31 PST 2026
================
@@ -160,30 +160,47 @@ static bool isOrderedSubset(ArrayRef<T> C0, ArrayRef<T> C1) {
return true;
}
+static bool hasUserConditionTrait(const VariantMatchInfo &VMI) {
+ for (TraitProperty Property :
+ {TraitProperty::user_condition_true, TraitProperty::user_condition_false,
+ TraitProperty::user_condition_unknown})
+ if (VMI.RequiredTraits.test(unsigned(Property)))
+ return true;
+ return false;
+}
+
+// A runtime condition can be left out of the traits but keep its key, so count
+// it as a trait.
+static unsigned countTraits(const VariantMatchInfo &VMI) {
+ return VMI.RequiredTraits.count() +
+ (!VMI.UserCondition.empty() && !hasUserConditionTrait(VMI));
+}
+
static bool isStrictSubset(const VariantMatchInfo &VMI0,
const VariantMatchInfo &VMI1) {
// VMI0 is a strict subset if its required traits are a subset of VMI1's, its
// construct traits are an ordered subsequence of VMI1's, and either relation
// is strict.
- if (VMI0.RequiredTraits.count() > VMI1.RequiredTraits.count())
+ if (countTraits(VMI0) > countTraits(VMI1))
return false;
for (unsigned Bit : VMI0.RequiredTraits.set_bits())
if (!VMI1.RequiredTraits.test(Bit))
return false;
+ // Different runtime conditions share a trait, so compare them as well.
+ if ((!VMI0.UserCondition.empty() || hasUserConditionTrait(VMI0)) &&
+ VMI0.UserCondition != VMI1.UserCondition)
+ return false;
if (!isOrderedSubset<TraitProperty>(VMI0.ConstructTraits,
VMI1.ConstructTraits))
return false;
- if (VMI0.RequiredTraits.count() < VMI1.RequiredTraits.count())
+ if (countTraits(VMI0) < countTraits(VMI1))
----------------
MattPD wrote:
Could `isStrictSubset` preserve ISA-name distinctions when the retained condition makes the count strict? [The baseline](https://github.com/llvm/llvm-project/commit/9f63b3c669b726e020a1f2a63e23c47d8349356c) selects TASKWAIT when `a` is false; the reviewed head emits unconditional TASKYIELD. Compile with `flang -fopenmp -fopenmp-version=52 -S -emit-llvm repro.f90 -o -`:
```fortran
subroutine isa_different(a)
logical, intent(in) :: a
!$omp metadirective when(device={isa(sse4)}, implementation={vendor(llvm), extension(match_any)}: taskwait) &
!$omp& when(user={condition(a)}, device={isa(avx)}, implementation={vendor(llvm), extension(match_any)}: taskyield)
end subroutine
```
Both selectors are applicable through `vendor(llvm)` and score five. Their ISA names differ, so neither is a subset and clause order requires TASKWAIT. For the second clause's unguarded candidate, the retained condition makes `countTraits(VMI0) < countTraits(VMI1)`, so `isStrictSubset` returns true without comparing ISA names. The base's true-`a` path was already wrong; the head's false path is newly wrong. Changing only `avx` to `sse4` correctly produces unconditional TASKYIELD on head.
https://github.com/llvm/llvm-project/pull/233493
More information about the cfe-commits
mailing list