================
@@ -157,24 +193,46 @@ template <typename T> static bool isSubset(ArrayRef<T> 
C0, ArrayRef<T> C1) {
       ++It1;
       continue;
     }
-    ++It0;
+    ++It1;
   }
   return true;
 }
 
 static bool isStrictSubset(const VariantMatchInfo &VMI0,
                            const VariantMatchInfo &VMI1) {
-  // If all required traits are a strict subset and the ordered vectors storing
-  // the construct traits, we say it is a strict subset. Note that the latter
-  // relation is not required to be strict.
-  if (VMI0.RequiredTraits.count() >= VMI1.RequiredTraits.count())
+  // kind(any) is equivalent to omitting the kind selector.
+  BitVector Traits0 = VMI0.RequiredTraits, Traits1 = VMI1.RequiredTraits;
+  for (TraitProperty Property : {TraitProperty::device_kind_any,
+                                 TraitProperty::target_device_kind_any}) {
+    Traits0.reset(unsigned(Property));
+    Traits1.reset(unsigned(Property));
+  }
+  size_t TraitCount0 = Traits0.count() + VMI0.UnknownTraits.size();
+  size_t TraitCount1 = Traits1.count() + VMI1.UnknownTraits.size();
+  if (TraitCount0 > TraitCount1)
     return false;
-  for (unsigned Bit : VMI0.RequiredTraits.set_bits())
-    if (!VMI1.RequiredTraits.test(Bit))
+  for (unsigned Bit : Traits0.set_bits())
+    if (!Traits1.test(Bit))
+      return false;
+  for (const auto &Trait : VMI0.UnknownTraits)
+    if (!llvm::is_contained(VMI1.UnknownTraits, Trait))
+      return false;
+  for (const auto &Trait : VMI0.ISATraits)
+    if (!llvm::is_contained(VMI1.ISATraits, Trait))
----------------
MattPD wrote:

The new ISA comparison also needs the property names preserved across PCH 
loading. `ASTWriter` still writes only `Property.Kind`, so both names become 
empty. With `match_any`, both candidates remain applicable and the new subset 
rule changes the selected callee.

Save this as `variant.h`:

```c
int v_avx512(void);
int v_sse2(void);
#pragma omp declare variant(v_avx512) match(device={isa(avx512f)}, 
implementation={vendor(score(100): llvm), extension(match_any)})
#pragma omp declare variant(v_sse2) match(device={isa(sse2)}, 
implementation={vendor(score(1): llvm), extension(match_any)}, 
user={condition(1)})
int isa_base(void);
```

Save `int isa_test(void) { return isa_base(); }` as `use.c`, then run:

```sh
clang -fopenmp -fopenmp-version=52 -x c-header variant.h -o variant.pch
clang -fopenmp -fopenmp-version=52 -include-pch variant.pch -S -emit-llvm use.c 
-o -
```

At 82f18330, `isa_test` calls `v_sse2`. With `-include variant.h` instead of 
`-include-pch variant.pch`, it calls `v_avx512`. At the 
[parent](https://github.com/llvm/llvm-project/commit/6544686b4a86193fc0bf6d229d59df20a4251e7f),
 it calls `v_avx512` in both forms. Could an ISA-name serialization fix and a 
PCH regression test accompany this comparison?

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

Reply via email to