================
@@ -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)) &&
----------------
MattPD wrote:

Could the repeated `SelectBestMetadirectiveCandidate` calls be profiled when 
each tied superset has a distinct condition?

For 160 logical elements `x(i)`, place 160 
`when(user={condition(score(1):x(i))}:taskyield)` clauses before 160 
`when(user={condition(x(i))},device={kind(cpu)}:taskwait)` clauses. Packing two 
TASKYIELD clauses per continuation line keeps the input within the Fortran 
continuation limit. All raw scores are two.

With `-fopenmp -fopenmp-version=52 -S -emit-llvm -ftime-report`, I measured 
7.4988 seconds in MLIR generation on the reviewed head versus 1.0931 seconds on 
[the 
baseline](https://github.com/llvm/llvm-project/commit/9f63b3c669b726e020a1f2a63e23c47d8349356c),
 while emitting the same LLVM IR apart from compiler identification. This 
baseline already includes the [merged tie-break 
change](https://github.com/llvm/llvm-project/pull/233905). With `x(1)` in every 
clause and the same command, I measured 0.0237 seconds on head and 0.0225 
seconds on the baseline.

https://github.com/llvm/llvm-project/pull/233493
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to