[clang] [CIR][X86] Add support for `cpuid`/`cpuidex` (PR #173197)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 8 17:58:55 PST 2026


================
@@ -3565,6 +3565,31 @@ cir::EhTypeIdOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
   return success();
 }
 
+//===----------------------------------------------------------------------===//
+// CpuIdOp
+//===----------------------------------------------------------------------===//
+
+LogicalResult cir::CpuIdOp::verify() {
+  auto basePtrTy = mlir::dyn_cast<cir::PointerType>(getBasePtr().getType());
+  if (!basePtrTy)
+    return mlir::failure();
+
+  mlir::Type type = basePtrTy.getPointee();
+
+  // basePtr points to an array of size at least 4
+  auto arrayTy = mlir::dyn_cast<cir::ArrayType>(type);
+  if (arrayTy && (arrayTy.getSize() < 4))
+    return emitOpError()
+           << "base pointer must point to an array of size at least 4";
+
+  // Array decay: basePtr points to !s32i
----------------
andykaylor wrote:

This is not necessarily an array decay. The user can pass any arbitrary pointer to integer to this function. For example: 

```
  int *cpuInfo = malloc(4 * sizeof(int));
  __cpuid((int *)&cpuInfo, functionId);
```

https://github.com/llvm/llvm-project/pull/173197


More information about the cfe-commits mailing list