Skip to content

Conversation

@Priyanshu3820
Copy link
Contributor

related to #167765

Calls the LLVM intrinsic for the following builtins-

BI__builtin_ia32_vcvtph2ps_mask
BI__builtin_ia32_vcvtph2ps256_mask
BI__builtin_ia32_vcvtph2ps512_mask
BI__builtin_ia32_cvtneps2bf16_128_mask
BI__builtin_ia32_cvtneps2bf16_256_mask
BI__builtin_ia32_cvtneps2bf16_512_mask

@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Dec 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 10, 2025

@llvm/pr-subscribers-backend-x86
@llvm/pr-subscribers-flang-semantics
@llvm/pr-subscribers-flang-openmp
@llvm/pr-subscribers-github-workflow
@llvm/pr-subscribers-backend-loongarch
@llvm/pr-subscribers-clang-temporal-safety
@llvm/pr-subscribers-clang-analysis
@llvm/pr-subscribers-hlsl
@llvm/pr-subscribers-pgo
@llvm/pr-subscribers-flang-driver
@llvm/pr-subscribers-bolt
@llvm/pr-subscribers-backend-m68k
@llvm/pr-subscribers-xray
@llvm/pr-subscribers-libcxx
@llvm/pr-subscribers-backend-powerpc
@llvm/pr-subscribers-clang-static-analyzer-1
@llvm/pr-subscribers-backend-systemz
@llvm/pr-subscribers-backend-mips
@llvm/pr-subscribers-clangd
@llvm/pr-subscribers-clangir

@llvm/pr-subscribers-clang

Author: Priyanshu Kumar (Priyanshu3820)

Changes

related to #167765

Calls the LLVM intrinsic for the following builtins-

BI__builtin_ia32_vcvtph2ps_mask
BI__builtin_ia32_vcvtph2ps256_mask
BI__builtin_ia32_vcvtph2ps512_mask
BI__builtin_ia32_cvtneps2bf16_128_mask
BI__builtin_ia32_cvtneps2bf16_256_mask
BI__builtin_ia32_cvtneps2bf16_512_mask


Full diff: https://github.com/llvm/llvm-project/pull/171615.diff

2 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp (+34-6)
  • (added) clang/test/CIR/CodeGen/X86/cir-convert-half.c (+55)
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
index fb17e31bf36d6..75022d4f93d4a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
@@ -1514,12 +1514,40 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
   case X86::BI__builtin_ia32_cmpnltsd:
   case X86::BI__builtin_ia32_cmpnlesd:
   case X86::BI__builtin_ia32_cmpordsd:
-  case X86::BI__builtin_ia32_vcvtph2ps_mask:
-  case X86::BI__builtin_ia32_vcvtph2ps256_mask:
-  case X86::BI__builtin_ia32_vcvtph2ps512_mask:
-  case X86::BI__builtin_ia32_cvtneps2bf16_128_mask:
-  case X86::BI__builtin_ia32_cvtneps2bf16_256_mask:
-  case X86::BI__builtin_ia32_cvtneps2bf16_512_mask:
+    cgm.errorNYI(expr->getSourceRange(),
+                 std::string("unimplemented X86 builtin call: ") +
+                     getContext().BuiltinInfo.getName(builtinID));
+    return {};
+  case X86::BI__builtin_ia32_vcvtph2ps_mask: {
+    mlir::Location loc = getLoc(expr->getExprLoc());
+    return emitIntrinsicCallOp(builder, loc, "x86.avx512.mask.vcvtph2ps.128",
+                               convertType(expr->getType()), ops);
+  }
+  case X86::BI__builtin_ia32_vcvtph2ps256_mask: {
+    mlir::Location loc = getLoc(expr->getExprLoc());
+    return emitIntrinsicCallOp(builder, loc, "x86.avx512.mask.vcvtph2ps.256",
+                               convertType(expr->getType()), ops);
+  }
+  case X86::BI__builtin_ia32_vcvtph2ps512_mask: {
+    mlir::Location loc = getLoc(expr->getExprLoc());
+    return emitIntrinsicCallOp(builder, loc, "x86.avx512.mask.vcvtph2ps.512",
+                               convertType(expr->getType()), ops);
+  }
+  case X86::BI__builtin_ia32_cvtneps2bf16_128_mask: {
+    mlir::Location loc = getLoc(expr->getExprLoc());
+    return emitIntrinsicCallOp(builder, loc, "x86.avx512bf16.mask.cvtneps2bf16.128",
+                               convertType(expr->getType()), ops);
+  }
+  case X86::BI__builtin_ia32_cvtneps2bf16_256_mask: {
+    mlir::Location loc = getLoc(expr->getExprLoc());
+    return emitIntrinsicCallOp(builder, loc, "x86.avx512bf16.cvtneps2bf16.256",
+                               convertType(expr->getType()), ops);
+  }
+  case X86::BI__builtin_ia32_cvtneps2bf16_512_mask: {
+    mlir::Location loc = getLoc(expr->getExprLoc());
+    return emitIntrinsicCallOp(builder, loc, "x86.avx512bf16.cvtneps2bf16.512",
+                               convertType(expr->getType()), ops);
+  }
   case X86::BI__cpuid:
   case X86::BI__cpuidex:
   case X86::BI__emul:
diff --git a/clang/test/CIR/CodeGen/X86/cir-convert-half.c b/clang/test/CIR/CodeGen/X86/cir-convert-half.c
new file mode 100644
index 0000000000000..4fad9aa02cfc1
--- /dev/null
+++ b/clang/test/CIR/CodeGen/X86/cir-convert-half.c
@@ -0,0 +1,55 @@
+// Test X86-specific convert_half builtins (4-argument form)
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +avx512fp16 -target-feature +avx512bf16 -fclangir -emit-cir %s -o - | FileCheck --check-prefix=CIR %s
+
+typedef float __m512 __attribute__((__vector_size__(64), __aligned__(64)));
+typedef float __m256 __attribute__((__vector_size__(32), __aligned__(32)));
+typedef float __m128 __attribute__((__vector_size__(16), __aligned__(16)));
+typedef int __m256i __attribute__((__vector_size__(32), __aligned__(32)));
+typedef int __m128i __attribute__((__vector_size__(16), __aligned__(16)));
+typedef int __mmask16;
+typedef unsigned char __mmask8;
+typedef __bf16 __m256bh __attribute__((__vector_size__(32), __aligned__(32)));
+typedef __bf16 __m128bh __attribute__((__vector_size__(16), __aligned__(16)));
+
+// Test for __builtin_ia32_vcvtph2ps512_mask
+__m512 test_vcvtph2ps512_mask(__m256i a, __m512 src, __mmask16 k, __m512 passthru) {
+  return __builtin_ia32_vcvtph2ps512_mask(a, src, k, passthru);
+}
+// CIR-LABEL: cir.func {{.*}}@test_vcvtph2ps512_mask
+// CIR: cir.call @llvm.x86.avx512.mask.vcvtph2ps.512
+
+// Test for __builtin_ia32_vcvtph2ps256_mask
+__m256 test_vcvtph2ps256_mask(__m128i a, __m256 src, __mmask8 k, __m256 passthru) {
+  return __builtin_ia32_vcvtph2ps256_mask(a, src, k, passthru);
+}
+// CIR-LABEL: cir.func {{.*}}@test_vcvtph2ps256_mask
+// CIR: cir.call @llvm.x86.avx512.mask.vcvtph2ps.256
+
+// Test for __builtin_ia32_vcvtph2ps_mask
+__m128 test_vcvtph2ps_mask(__m128i a, __m128 src, __mmask8 k, __m128 passthru) {
+  return __builtin_ia32_vcvtph2ps_mask(a, src, k, passthru);
+}
+// CIR-LABEL: cir.func {{.*}}@test_vcvtph2ps_mask
+// CIR: cir.call @llvm.x86.avx512.mask.vcvtph2ps.128
+
+// Test for __builtin_ia32_cvtneps2bf16_512_mask
+__m256bh test_cvtneps2bf16_512_mask(__m512 a, __m256bh w, __mmask16 u, __m256bh passthru) {
+  return __builtin_ia32_cvtneps2bf16_512_mask(a, w, u, passthru);
+}
+// CIR-LABEL: cir.func {{.*}}@test_cvtneps2bf16_512_mask
+// CIR: cir.call @llvm.x86.avx512bf16.cvtneps2bf16.512
+
+// Test for __builtin_ia32_cvtneps2bf16_256_mask
+__m128bh test_cvtneps2bf16_256_mask(__m256 a, __m128bh w, __mmask8 u, __m128bh passthru) {
+  return __builtin_ia32_cvtneps2bf16_256_mask(a, w, u, passthru);
+}
+// CIR-LABEL: cir.func {{.*}}@test_cvtneps2bf16_256_mask
+// CIR: cir.call @llvm.x86.avx512bf16.cvtneps2bf16.256
+
+// Test for __builtin_ia32_cvtneps2bf16_128_mask
+__m128bh test_cvtneps2bf16_128_mask(__m128 a, __m128bh w, __mmask8 u, __m128bh passthru) {
+  return __builtin_ia32_cvtneps2bf16_128_mask(a, w, u, passthru);
+}
+// CIR-LABEL: cir.func {{.*}}@test_cvtneps2bf16_128_mask
+// CIR: cir.call @llvm.x86.avx512bf16.mask.cvtneps2bf16.128
\ No newline at end of file

@github-actions
Copy link

github-actions bot commented Dec 10, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@Priyanshu3820 Priyanshu3820 changed the title [CIR][X86] Implement convert_half builtin [CIR][X86] Implement convert_half builtins Dec 10, 2025
@github-actions
Copy link

github-actions bot commented Dec 10, 2025

🐧 Linux x64 Test Results

  • 86065 tests passed
  • 757 tests skipped
  • 2 tests failed

Failed Tests

(click on a test name to see its output)

Clang

Clang.CIR/CodeGenBuiltins/X86/avx512vlbf16-builtins.c
Exit Code: -6

Command Output (stdout):
--
# RUN: at line 1
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/22/include -nostdsysteminc -flax-vector-conversions=none -ffreestanding /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenBuiltins/X86/avx512vlbf16-builtins.c -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx512bf16 -fclangir -emit-cir -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGenBuiltins/X86/Output/avx512vlbf16-builtins.c.tmp.cir -Wall -Werror -Wsign-conversion
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/22/include -nostdsysteminc -flax-vector-conversions=none -ffreestanding /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenBuiltins/X86/avx512vlbf16-builtins.c -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx512bf16 -fclangir -emit-cir -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGenBuiltins/X86/Output/avx512vlbf16-builtins.c.tmp.cir -Wall -Werror -Wsign-conversion
# .---command stderr------------
# | clang: /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include/llvm/Support/Casting.h:560: decltype(auto) llvm::cast(const From &) [To = cir::IntType, From = mlir::Type]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
# | Stack dump:
# | 0.	Program arguments: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/22/include -nostdsysteminc -flax-vector-conversions=none -ffreestanding /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenBuiltins/X86/avx512vlbf16-builtins.c -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx512bf16 -fclangir -emit-cir -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGenBuiltins/X86/Output/avx512vlbf16-builtins.c.tmp.cir -Wall -Werror -Wsign-conversion
# | 1.	<eof> parser at end of file
# |  #0 0x0000000009963158 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Unix/Signals.inc:842:13
# |  #1 0x0000000009960821 llvm::sys::RunSignalHandlers() /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Signals.cpp:109:18
# |  #2 0x0000000009963f21 SignalHandler(int, siginfo_t*, void*) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Unix/Signals.inc:429:38
# |  #3 0x00007ff9a5924330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
# |  #4 0x00007ff9a597db2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
# |  #5 0x00007ff9a592427e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
# |  #6 0x00007ff9a59078ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
# |  #7 0x00007ff9a590781b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
# |  #8 0x00007ff9a591a517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
# |  #9 0x000000000aafbae8 getMaskVecValue(clang::CIRGen::CIRGenBuilderTy&, mlir::Location, mlir::Value, unsigned int) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp:0:0
# | #10 0x000000000aafbed7 emitX86Select(clang::CIRGen::CIRGenBuilderTy&, mlir::Location, mlir::Value, mlir::Value, mlir::Value) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp:181:8
# | #11 0x000000000aaf9d62 clang::CIRGen::CIRGenFunction::emitX86BuiltinExpr(unsigned int, clang::CallExpr const*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp:0:0
# | #12 0x000000000aaf16f0 clang::CIRGen::CIRGenFunction::emitTargetBuiltinExpr(unsigned int, clang::CallExpr const*, clang::CIRGen::ReturnValueSlot&) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp:1463:1
# | #13 0x000000000aaecd56 clang::CIRGen::CIRGenFunction::emitBuiltinExpr(clang::GlobalDecl const&, unsigned int, clang::CallExpr const*, clang::CIRGen::ReturnValueSlot) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp:1365:34
# | #14 0x000000000aae2116 clang::CIRGen::CIRGenFunction::emitCallExpr(clang::CallExpr const*, clang::CIRGen::ReturnValueSlot) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenExpr.cpp:2082:5
# | #15 0x000000000ab28cd2 isScalar /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenValue.h:49:41
# | #16 0x000000000ab28cd2 getValue /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenValue.h:58:5
# | #17 0x000000000ab28cd2 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp:2325:32
# | #18 0x000000000ab2bad2 Visit /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp:130:57
# | #19 0x000000000ab2bad2 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp:2063:23
# | #20 0x000000000ab1f845 clang::CIRGen::CIRGenFunction::emitScalarExpr(clang::Expr const*, bool) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp:1635:3
# | #21 0x000000000ab76c0b operator bool /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/../mlir/include/mlir/IR/Value.h:100:43
# | #22 0x000000000ab76c0b clang::CIRGen::CIRGenFunction::emitReturnStmt(clang::ReturnStmt const&)::$_0::operator()() const /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenStmt.cpp:598:13
# | #23 0x000000000ab76533 clang::CIRGen::CIRGenFunction::emitReturnStmt(clang::ReturnStmt const&) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenStmt.cpp:620:3
# | #24 0x000000000ab7455c clang::CIRGen::CIRGenFunction::emitStmt(clang::Stmt const*, bool, llvm::ArrayRef<clang::Attr const*>) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenStmt.cpp:0:23
# | #25 0x000000000ab74493 clang::CIRGen::CIRGenFunction::emitCompoundStmtWithoutScope(clang::CompoundStmt const&, clang::CIRGen::Address*, clang::CIRGen::AggValueSlot) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenStmt.cpp:81:11
# | #26 0x000000000ab3248f emitFunctionBody /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenFunction.cpp:646:12
# | #27 0x000000000ab3248f clang::CIRGen::CIRGenFunction::generateCode(clang::GlobalDecl, cir::FuncOp, cir::FuncType) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenFunction.cpp:764:24
# | #28 0x000000000ab391f8 isSet /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/../mlir/include/mlir/IR/Builders.h:337:40
# | #29 0x000000000ab391f8 restoreInsertionPoint /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/../mlir/include/mlir/IR/Builders.h:391:12
# | #30 0x000000000ab391f8 ~InsertionGuard /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/../mlir/include/mlir/IR/Builders.h:355:18
# | #31 0x000000000ab391f8 clang::CIRGen::CIRGenModule::emitGlobalFunctionDefinition(clang::GlobalDecl, mlir::Operation*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenModule.cpp:460:3
# | #32 0x000000000ab3847f clang::CIRGen::CIRGenModule::emitGlobalDefinition(clang::GlobalDecl, mlir::Operation*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenModule.cpp:956:5
# | #33 0x000000000ab38029 clang::CIRGen::CIRGenModule::emitGlobalDecl(clang::GlobalDecl const&) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenModule.cpp:328:1
# | #34 0x000000000ab385f4 __normal_iterator /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_iterator.h:1077:20
# | #35 0x000000000ab385f4 begin /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_vector.h:884:16
# | #36 0x000000000ab385f4 empty /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_vector.h:1089:16
# | #37 0x000000000ab385f4 clang::CIRGen::CIRGenModule::emitDeferred() /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenModule.cpp:354:30
# | #38 0x000000000ab40e3f clang::CIRGen::CIRGenModule::release() /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenModule.cpp:2588:3
# | #39 0x000000000a9ab400 cir::CIRGenConsumer::HandleTranslationUnit(clang::ASTContext&) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/FrontendAction/CIRGenAction.cpp:103:10
# | #40 0x000000000cc40ea9 __normal_iterator /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_iterator.h:1077:20
# | #41 0x000000000cc40ea9 begin /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_vector.h:874:16
# | #42 0x000000000cc40ea9 finalize<std::vector<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback> >, std::allocator<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback> > > > > /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/include/clang/Sema/TemplateInstCallback.h:54:16
# | #43 0x000000000cc40ea9 clang::ParseAST(clang::Sema&, bool, bool) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/Parse/ParseAST.cpp:190:3
# | #44 0x000000000a639346 clang::FrontendAction::Execute() /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1316:10
# | #45 0x000000000a5a037d getPtr /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include/llvm/Support/Error.h:278:42
# | #46 0x000000000a5a037d operator bool /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include/llvm/Support/Error.h:241:16
# | #47 0x000000000a5a037d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1003:23
# | #48 0x000000000a72bfcf clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:310:25
# | #49 0x0000000006cb8165 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/tools/driver/cc1_main.cpp:304:15
# | #50 0x0000000006cb3ee5 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/tools/driver/driver.cpp:225:12
# | #51 0x0000000006cb2f4d clang_main(int, char**, llvm::ToolContext const&) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/tools/driver/driver.cpp:268:12
# | #52 0x0000000006cc4037 main /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/driver/clang-driver.cpp:17:10
# | #53 0x00007ff9a59091ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
# | #54 0x00007ff9a590928b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
# | #55 0x0000000006cb1925 _start (/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang+0x6cb1925)
# `-----------------------------
# error: command failed with exit status: -6

--

Clang.CIR/CodeGenBuiltins/X86/avx512vlbf16-builtins.c
Exit Code: -6

Command Output (stdout):
--
# RUN: at line 1
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/22/include -nostdsysteminc -flax-vector-conversions=none -ffreestanding /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenBuiltins/X86/avx512vlbf16-builtins.c -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx512bf16 -fclangir -emit-cir -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGenBuiltins/X86/Output/avx512vlbf16-builtins.c.tmp.cir -Wall -Werror -Wsign-conversion
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/22/include -nostdsysteminc -flax-vector-conversions=none -ffreestanding /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenBuiltins/X86/avx512vlbf16-builtins.c -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx512bf16 -fclangir -emit-cir -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGenBuiltins/X86/Output/avx512vlbf16-builtins.c.tmp.cir -Wall -Werror -Wsign-conversion
# .---command stderr------------
# | clang: /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include/llvm/Support/Casting.h:560: decltype(auto) llvm::cast(const From &) [To = cir::IntType, From = mlir::Type]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
# | Stack dump:
# | 0.	Program arguments: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/22/include -nostdsysteminc -flax-vector-conversions=none -ffreestanding /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenBuiltins/X86/avx512vlbf16-builtins.c -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx512bf16 -fclangir -emit-cir -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGenBuiltins/X86/Output/avx512vlbf16-builtins.c.tmp.cir -Wall -Werror -Wsign-conversion
# | 1.	<eof> parser at end of file
# |  #0 0x0000000009963158 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Unix/Signals.inc:842:13
# |  #1 0x0000000009960821 llvm::sys::RunSignalHandlers() /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Signals.cpp:109:18
# |  #2 0x0000000009963f21 SignalHandler(int, siginfo_t*, void*) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Unix/Signals.inc:429:38
# |  #3 0x00007d9da9b9b330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
# |  #4 0x00007d9da9bf4b2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
# |  #5 0x00007d9da9b9b27e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
# |  #6 0x00007d9da9b7e8ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
# |  #7 0x00007d9da9b7e81b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
# |  #8 0x00007d9da9b91517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
# |  #9 0x000000000aafbae8 getMaskVecValue(clang::CIRGen::CIRGenBuilderTy&, mlir::Location, mlir::Value, unsigned int) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp:0:0
# | #10 0x000000000aafbed7 emitX86Select(clang::CIRGen::CIRGenBuilderTy&, mlir::Location, mlir::Value, mlir::Value, mlir::Value) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp:181:8
# | #11 0x000000000aaf9d62 clang::CIRGen::CIRGenFunction::emitX86BuiltinExpr(unsigned int, clang::CallExpr const*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp:0:0
# | #12 0x000000000aaf16f0 clang::CIRGen::CIRGenFunction::emitTargetBuiltinExpr(unsigned int, clang::CallExpr const*, clang::CIRGen::ReturnValueSlot&) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp:1463:1
# | #13 0x000000000aaecd56 clang::CIRGen::CIRGenFunction::emitBuiltinExpr(clang::GlobalDecl const&, unsigned int, clang::CallExpr const*, clang::CIRGen::ReturnValueSlot) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp:1365:34
# | #14 0x000000000aae2116 clang::CIRGen::CIRGenFunction::emitCallExpr(clang::CallExpr const*, clang::CIRGen::ReturnValueSlot) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenExpr.cpp:2082:5
# | #15 0x000000000ab28cd2 isScalar /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenValue.h:49:41
# | #16 0x000000000ab28cd2 getValue /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenValue.h:58:5
# | #17 0x000000000ab28cd2 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp:2325:32
# | #18 0x000000000ab2bad2 Visit /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp:130:57
# | #19 0x000000000ab2bad2 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp:2063:23
# | #20 0x000000000ab1f845 clang::CIRGen::CIRGenFunction::emitScalarExpr(clang::Expr const*, bool) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp:1635:3
# | #21 0x000000000ab76c0b operator bool /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/../mlir/include/mlir/IR/Value.h:100:43
# | #22 0x000000000ab76c0b clang::CIRGen::CIRGenFunction::emitReturnStmt(clang::ReturnStmt const&)::$_0::operator()() const /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenStmt.cpp:598:13
# | #23 0x000000000ab76533 clang::CIRGen::CIRGenFunction::emitReturnStmt(clang::ReturnStmt const&) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenStmt.cpp:620:3
# | #24 0x000000000ab7455c clang::CIRGen::CIRGenFunction::emitStmt(clang::Stmt const*, bool, llvm::ArrayRef<clang::Attr const*>) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenStmt.cpp:0:23
# | #25 0x000000000ab74493 clang::CIRGen::CIRGenFunction::emitCompoundStmtWithoutScope(clang::CompoundStmt const&, clang::CIRGen::Address*, clang::CIRGen::AggValueSlot) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenStmt.cpp:81:11
# | #26 0x000000000ab3248f emitFunctionBody /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenFunction.cpp:646:12
# | #27 0x000000000ab3248f clang::CIRGen::CIRGenFunction::generateCode(clang::GlobalDecl, cir::FuncOp, cir::FuncType) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenFunction.cpp:764:24
# | #28 0x000000000ab391f8 isSet /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/../mlir/include/mlir/IR/Builders.h:337:40
# | #29 0x000000000ab391f8 restoreInsertionPoint /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/../mlir/include/mlir/IR/Builders.h:391:12
# | #30 0x000000000ab391f8 ~InsertionGuard /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/../mlir/include/mlir/IR/Builders.h:355:18
# | #31 0x000000000ab391f8 clang::CIRGen::CIRGenModule::emitGlobalFunctionDefinition(clang::GlobalDecl, mlir::Operation*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenModule.cpp:460:3
# | #32 0x000000000ab3847f clang::CIRGen::CIRGenModule::emitGlobalDefinition(clang::GlobalDecl, mlir::Operation*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenModule.cpp:956:5
# | #33 0x000000000ab38029 clang::CIRGen::CIRGenModule::emitGlobalDecl(clang::GlobalDecl const&) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenModule.cpp:328:1
# | #34 0x000000000ab385f4 __normal_iterator /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_iterator.h:1077:20
# | #35 0x000000000ab385f4 begin /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_vector.h:884:16
# | #36 0x000000000ab385f4 empty /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_vector.h:1089:16
# | #37 0x000000000ab385f4 clang::CIRGen::CIRGenModule::emitDeferred() /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenModule.cpp:354:30
# | #38 0x000000000ab40e3f clang::CIRGen::CIRGenModule::release() /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenModule.cpp:2588:3
# | #39 0x000000000a9ab400 cir::CIRGenConsumer::HandleTranslationUnit(clang::ASTContext&) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/FrontendAction/CIRGenAction.cpp:103:10
# | #40 0x000000000cc40ea9 __normal_iterator /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_iterator.h:1077:20
# | #41 0x000000000cc40ea9 begin /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_vector.h:874:16
# | #42 0x000000000cc40ea9 finalize<std::vector<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback> >, std::allocator<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback> > > > > /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/include/clang/Sema/TemplateInstCallback.h:54:16
# | #43 0x000000000cc40ea9 clang::ParseAST(clang::Sema&, bool, bool) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/Parse/ParseAST.cpp:190:3
# | #44 0x000000000a639346 clang::FrontendAction::Execute() /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1316:10
# | #45 0x000000000a5a037d getPtr /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include/llvm/Support/Error.h:278:42
# | #46 0x000000000a5a037d operator bool /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include/llvm/Support/Error.h:241:16
# | #47 0x000000000a5a037d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1003:23
# | #48 0x000000000a72bfcf clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:310:25
# | #49 0x0000000006cb8165 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/tools/driver/cc1_main.cpp:304:15
# | #50 0x0000000006cb3ee5 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/tools/driver/driver.cpp:225:12
# | #51 0x0000000006cb2f4d clang_main(int, char**, llvm::ToolContext const&) /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/tools/driver/driver.cpp:268:12
# | #52 0x0000000006cc4037 main /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/driver/clang-driver.cpp:17:10
# | #53 0x00007d9da9b801ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
# | #54 0x00007d9da9b8028b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
# | #55 0x0000000006cb1925 _start (/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang+0x6cb1925)
# `-----------------------------
# error: command failed with exit status: -6

--

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

Copy link
Contributor

@badumbatish badumbatish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use clang/tools/clang-format/git-clang-format --binary ./build/bin/clang-format HEAD~1 to format your changes so it doesn't trigger the CI warning.

Comment on lines 1521 to 1695
case X86::BI__builtin_ia32_vcvtph2ps_mask: {
mlir::Location loc = getLoc(expr->getExprLoc());
return emitIntrinsicCallOp(builder, loc, "x86.avx512.mask.vcvtph2ps.128",
convertType(expr->getType()), ops);
}
case X86::BI__builtin_ia32_vcvtph2ps256_mask: {
mlir::Location loc = getLoc(expr->getExprLoc());
return emitIntrinsicCallOp(builder, loc, "x86.avx512.mask.vcvtph2ps.256",
convertType(expr->getType()), ops);
}
case X86::BI__builtin_ia32_vcvtph2ps512_mask: {
mlir::Location loc = getLoc(expr->getExprLoc());
return emitIntrinsicCallOp(builder, loc, "x86.avx512.mask.vcvtph2ps.512",
convertType(expr->getType()), ops);
}
case X86::BI__builtin_ia32_cvtneps2bf16_128_mask: {
mlir::Location loc = getLoc(expr->getExprLoc());
return emitIntrinsicCallOp(builder, loc, "x86.avx512bf16.mask.cvtneps2bf16.128",
convertType(expr->getType()), ops);
}
case X86::BI__builtin_ia32_cvtneps2bf16_256_mask: {
mlir::Location loc = getLoc(expr->getExprLoc());
return emitIntrinsicCallOp(builder, loc, "x86.avx512bf16.cvtneps2bf16.256",
convertType(expr->getType()), ops);
}
case X86::BI__builtin_ia32_cvtneps2bf16_512_mask: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heyya, for this you should implement sth akin to below to save on space and readability

  case X86::BI__builtin_ia32_reduce_fmax_pd512:
  case X86::BI__builtin_ia32_reduce_fmax_ps512:
  case X86::BI__builtin_ia32_reduce_fmax_ph512:
  case X86::BI__builtin_ia32_reduce_fmax_ph256:
  case X86::BI__builtin_ia32_reduce_fmax_ph128: {
    StringRef intrinsicName = "";
    switch (builtinID) {
    case X86::BI__builtin_ia32_reduce_fmax_pd512:
      intrinsicName = "vector.reduce.fmax.v8f64";
      break;
    case X86::BI__builtin_ia32_reduce_fmax_ps512:
      intrinsicName = "vector.reduce.fmax.v16f32";
      break;
    case X86::BI__builtin_ia32_reduce_fmax_ph512:
      intrinsicName = "vector.reduce.fmax.v32f16";
      break;
    case X86::BI__builtin_ia32_reduce_fmax_ph256:
      intrinsicName = "vector.reduce.fmax.v16f16";
      break;
    case X86::BI__builtin_ia32_reduce_fmax_ph128:
      intrinsicName = "vector.reduce.fmax.v8f16";
      break;
    }
    return emitIntrinsicCallOp(...);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heyya, for this you should implement sth akin to below to save on space and readability

  case X86::BI__builtin_ia32_reduce_fmax_pd512:
  case X86::BI__builtin_ia32_reduce_fmax_ps512:
  case X86::BI__builtin_ia32_reduce_fmax_ph512:
  case X86::BI__builtin_ia32_reduce_fmax_ph256:
  case X86::BI__builtin_ia32_reduce_fmax_ph128: {
    StringRef intrinsicName = "";
    switch (builtinID) {
    case X86::BI__builtin_ia32_reduce_fmax_pd512:
      intrinsicName = "vector.reduce.fmax.v8f64";
      break;
    case X86::BI__builtin_ia32_reduce_fmax_ps512:
      intrinsicName = "vector.reduce.fmax.v16f32";
      break;
    case X86::BI__builtin_ia32_reduce_fmax_ph512:
      intrinsicName = "vector.reduce.fmax.v32f16";
      break;
    case X86::BI__builtin_ia32_reduce_fmax_ph256:
      intrinsicName = "vector.reduce.fmax.v16f16";
      break;
    case X86::BI__builtin_ia32_reduce_fmax_ph128:
      intrinsicName = "vector.reduce.fmax.v8f16";
      break;
    }
    return emitIntrinsicCallOp(...);

I too considered this way and I take it that it's your implementation of the reduce intrinsics right? But I think we are supposed to follow the already established pattern aren't we? I would be more than happy to implement this way though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I too considered this way and I take it that it's your implementation of the reduce intrinsics right? But I think we are supposed to follow the already established pattern aren't we? I would be more than happy to implement this way though.

In general, we are trying to follow the established code patterns, but if the code can be improved it's OK to diverge. I like the suggestion from @badumbatish here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do it that way then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I too considered this way and I take it that it's your implementation of the reduce intrinsics right? But I think we are supposed to follow the already established pattern aren't we? I would be more than happy to implement this way though.

In general, we are trying to follow the established code patterns, but if the code can be improved it's OK to diverge. I like the suggestion from @badumbatish here.

updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably go into a new file inside clang/test/CIR/CodeGenBuiltins/X86/ to match OG's clang/test/CodeGen/X86/avx512vlbf16-builtins.c.

You can check out that file to import all the test over as well.

Don't forget to set up 3 prefix: CIR, LLVM and OGCG as well, see clang/test/CIR/CodeGenBuiltins/X86/avx512fp16-builtins.c for details

@Priyanshu3820
Copy link
Contributor Author

you can use clang/tools/clang-format/git-clang-format --binary ./build/bin/clang-format HEAD~1 to format your changes so it doesn't trigger the CI warning.

done

@github-actions
Copy link

github-actions bot commented Dec 11, 2025

✅ With the latest revision this PR passed the Python code formatter.

@Priyanshu3820
Copy link
Contributor Author

@andykaylor, the CI checks are failing and the build log is saying this-

/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenStmt.cpp:117:11: error: enumeration value 'DeferStmtClass' not handled in switch [-Werror,-Wswitch] 117 | switch (s->getStmtClass()) { | ^~~~~~~~~~~~~~~~~ 1 error generated. ninja: build stopped: cannot make progress due to previous errors.

Neither did I edit this file nor does it contain DeferStmtClass in my local build. I rebased but still it's not there. I don't understand why is it happening.

@andykaylor
Copy link
Contributor

@andykaylor, the CI checks are failing and the build log is saying this-

/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenStmt.cpp:117:11: error: enumeration value 'DeferStmtClass' not handled in switch [-Werror,-Wswitch] 117 | switch (s->getStmtClass()) { | ^~~~~~~~~~~~~~~~~ 1 error generated. ninja: build stopped: cannot make progress due to previous errors.

Neither did I edit this file nor does it contain DeferStmtClass in my local build. I rebased but still it's not there. I don't understand why is it happening.

DeferStmtClass was added by a change unrelated to CIR and since the CIR build is disabled by default, this issue wasn't caught in CI or by the buildbots. @badumbatish has fixed it here: #171773. If you rebase your PR, the CIR checks should work.

@Priyanshu3820
Copy link
Contributor Author

@andykaylor, the CI checks are failing and the build log is saying this-
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenStmt.cpp:117:11: error: enumeration value 'DeferStmtClass' not handled in switch [-Werror,-Wswitch] 117 | switch (s->getStmtClass()) { | ^~~~~~~~~~~~~~~~~ 1 error generated. ninja: build stopped: cannot make progress due to previous errors.
Neither did I edit this file nor does it contain DeferStmtClass in my local build. I rebased but still it's not there. I don't understand why is it happening.

DeferStmtClass was added by a change unrelated to CIR and since the CIR build is disabled by default, this issue wasn't caught in CI or by the buildbots. @badumbatish has fixed it here: #171773. If you rebase your PR, the CIR checks should work.

Yes, they worked this time.
And thanks for handling this @badumbatish

Comment on lines 1521 to 1695
case X86::BI__builtin_ia32_vcvtph2ps_mask: {
mlir::Location loc = getLoc(expr->getExprLoc());
return emitIntrinsicCallOp(builder, loc, "x86.avx512.mask.vcvtph2ps.128",
convertType(expr->getType()), ops);
}
case X86::BI__builtin_ia32_vcvtph2ps256_mask: {
mlir::Location loc = getLoc(expr->getExprLoc());
return emitIntrinsicCallOp(builder, loc, "x86.avx512.mask.vcvtph2ps.256",
convertType(expr->getType()), ops);
}
case X86::BI__builtin_ia32_vcvtph2ps512_mask: {
mlir::Location loc = getLoc(expr->getExprLoc());
return emitIntrinsicCallOp(builder, loc, "x86.avx512.mask.vcvtph2ps.512",
convertType(expr->getType()), ops);
}
case X86::BI__builtin_ia32_cvtneps2bf16_128_mask: {
mlir::Location loc = getLoc(expr->getExprLoc());
return emitIntrinsicCallOp(builder, loc, "x86.avx512bf16.mask.cvtneps2bf16.128",
convertType(expr->getType()), ops);
}
case X86::BI__builtin_ia32_cvtneps2bf16_256_mask: {
mlir::Location loc = getLoc(expr->getExprLoc());
return emitIntrinsicCallOp(builder, loc, "x86.avx512bf16.cvtneps2bf16.256",
convertType(expr->getType()), ops);
}
case X86::BI__builtin_ia32_cvtneps2bf16_512_mask: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I too considered this way and I take it that it's your implementation of the reduce intrinsics right? But I think we are supposed to follow the already established pattern aren't we? I would be more than happy to implement this way though.

In general, we are trying to follow the established code patterns, but if the code can be improved it's OK to diverge. I like the suggestion from @badumbatish here.

// OGCG-LABEL: test_cvtneps2bf16_128_mask
__bf16 test_cvtneps2bf16_128_mask(__m128 a, __bf16 w, __mmask8 u) {
return __builtin_ia32_cvtneps2bf16_128_mask(a, w, u);
} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a newline at the end of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

case X86::BI__builtin_ia32_cvtneps2bf16_256_mask:
intrinsicName = "x86.avx512bf16.cvtneps2bf16.256";
break;
case X86::BI__builtin_ia32_cvtneps2bf16_512_mask:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to follow the intrinsic with a select operation for BI__builtin_ia32_cvtneps2bf16_256_mask and BI__builtin_ia32_cvtneps2bf16_512_mask

case X86::BI__builtin_ia32_vcvtph2ps256_mask:
intrinsicName = "x86.avx512.mask.vcvtph2ps.256";
break;
case X86::BI__builtin_ia32_vcvtph2ps512_mask:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BI__builtin_ia32_vcvtph2ps_mask, BI__builtin_ia32_vcvtph2ps256_mask, and BI__builtin_ia32_vcvtph2ps512_mask aren't this simple. In classic codegen they are implemented with a call to EmitX86CvtF16ToFloatExpr, which has quite a bit more code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, we'll need to create a helper like EmitX86CvtF16ToFloatExpr in CIR first, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, except in CIR it should be emitX86CvtF16ToFloatExpr due to our slightly different coding style.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it as emitCIRX86CvtF16ToFloatExpr. Should I rename?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i renamed it to emitX86CvtF16ToFloatExpr, @andykaylor

// LLVM-LABEL: test_vcvtph2ps512_mask
// OGCG-LABEL: test_vcvtph2ps512_mask
__m512 test_vcvtph2ps512_mask(__m256i a, __m512 src, __mmask16 k) {
return __builtin_ia32_vcvtph2ps512_mask(a, src, k, 4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than creating a new test and calling these builtins directly, you should create clang/test/CIR/CodeGenBuiltins/X86/avx512vlbf16-builtins.c and test these by calling the wrapper functions defined in clang/lib/Headers/avx512vlbf16intrin.h. You may use clang/test/CodeGen/X86/avx512vlbf16-builtins.c as a starting point, but you'll need to change the RUN lines and the checks, and you won't want to copy unrelated tests.

Comment on lines 31 to 32
// LLVM-LABEL: test_vcvtph2ps256_mask
// OGCG-LABEL: test_vcvtph2ps256_mask
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks are not doing anything useful. You should have check lines that show the details of the intrinsic call that was generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project

Projects

None yet

Development

Successfully merging this pull request may close these issues.