Skip to content

[CIR] Use -verify on clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl - #182817

Merged
Men-cotton merged 4 commits into
llvm:mainfrom
Men-cotton:Men-cotton/matrix-element-expr-load
Feb 28, 2026
Merged

Men-cotton merged 4 commits into
llvm:mainfrom
Men-cotton:Men-cotton/matrix-element-expr-load

Conversation

@Men-cotton

@Men-cotton Men-cotton commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

Update clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl to use -verify with expected CIR NYI diagnostics.

@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Feb 23, 2026
@llvmbot

llvmbot commented Feb 23, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-clangir

@llvm/pr-subscribers-clang

Author: Akimasa Watanuki (Men-cotton)

Changes

In ScalarExprEmitter::VisitCastExpr, guard CK_VectorSplat so cir::VecSplatOp is only created for a valid scalar value.

Update clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl to use -verify with expected CIR NYI diagnostics.


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

2 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+4-1)
  • (modified) clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl (+6-6)
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index d523aa2fdb737..e5f17d720ee86 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -2371,9 +2371,12 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) {
   case CK_VectorSplat: {
     // Create a vector object and fill all elements with the same scalar value.
     assert(destTy->isVectorType() && "CK_VectorSplat to non-vector type");
+    mlir::Value scalar = Visit(subExpr);
+    if (!scalar)
+      return {};
     return cir::VecSplatOp::create(builder,
                                    cgf.getLoc(subExpr->getSourceRange()),
-                                   cgf.convertType(destTy), Visit(subExpr));
+                                   cgf.convertType(destTy), scalar);
   }
   case CK_FunctionToPointerDecay:
     return cgf.emitLValue(subExpr).getPointer();
diff --git a/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl b/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl
index 279075a6dab60..f3c6d1fefd1f0 100644
--- a/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl
+++ b/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl
@@ -1,8 +1,8 @@
-// RUN: not %clang_cc1 -x hlsl -finclude-default-header -triple spirv-unknown-vulkan-compute %s \
-// RUN:   -fclangir -emit-cir -disable-llvm-passes 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -x hlsl -finclude-default-header -triple spirv-unknown-vulkan-compute %s \
+// RUN:   -fclangir -emit-cir -disable-llvm-passes -verify
 
-// CHECK: ClangIR code gen Not Yet Implemented: processing of type: ConstantMatrix
-float1 test_zero_indexed(float2x2 M) { 
-  // CHECK: ClangIR code gen Not Yet Implemented: ScalarExprEmitter: matrix element
-  return M._m00; 
+// expected-error@*:* {{ClangIR code gen Not Yet Implemented: processing of type: ConstantMatrix}}
+float1 test_zero_indexed(float2x2 M) {
+  // expected-error@+1 {{ClangIR code gen Not Yet Implemented: ScalarExprEmitter: matrix element}}
+  return M._m00;
 }

@Men-cotton

Copy link
Copy Markdown
Contributor Author

The motivation behind this PR is to resolve the following error seen in recent CI checks:

Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
not /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/23/include -nostdsysteminc -x hlsl -finclude-default-header -triple spirv-unknown-vulkan-compute /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl    -fclangir -emit-cir -disable-llvm-passes 2>&1 | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl
# executed command: not /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/23/include -nostdsysteminc -x hlsl -finclude-default-header -triple spirv-unknown-vulkan-compute /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl -fclangir -emit-cir -disable-llvm-passes
# note: command had no output on stdout or stderr
# error: command failed with exit status: 1
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl
# note: command had no output on stdout or stderr

--

@erichkeane erichkeane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note I merged a fix for this test yesterday as well that was to just update the test to use float instead of float1, so it doesn't fail.

However, the 'crash' we're hitting is because of an NYI. And this fix just 'passes' the failure onto the caller of this, and will cause the same problems elsewhere.

IMO, we don't want to be doing this.

// Create a vector object and fill all elements with the same scalar value.
assert(destTy->isVectorType() && "CK_VectorSplat to non-vector type");
mlir::Value scalar = Visit(subExpr);
if (!scalar)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

THIS is something that should never happen, right? It only does because we're not yet implemented. IMO, we shouldn't introduce a branch that should go away later.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

float test_zero_indexed(float2x2 M) {
// CHECK: ClangIR code gen Not Yet Implemented: ScalarExprEmitter: matrix element
return M._m00;
// expected-error@*:* {{ClangIR code gen Not Yet Implemented: processing of type: ConstantMatrix}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is probably not a bad change either.

@farzonl

farzonl commented Feb 24, 2026

Copy link
Copy Markdown
Member

Approved for the test change. The rest should be reviewed by a CIR developer

@github-actions

github-actions Bot commented Feb 24, 2026

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 115352 tests passed
  • 4049 tests skipped

✅ The build succeeded and all tests passed.

@Men-cotton Men-cotton changed the title [CIR] Guard CK_VectorSplat on failed scalar emission [CIR] Use -verify on clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl Feb 25, 2026
@Men-cotton

Men-cotton commented Feb 25, 2026

Copy link
Copy Markdown
Contributor Author

I've reverted the CK_VectorSplat patch. The PR is now scoped solely to cleaning up the test by using -verify.

I noticed there are other tests in clang/test/CIR still relying on the 2>&1 redirection pattern: https://github.com/search?q=repo%3Allvm%2Fllvm-project+%222%3E%261%22+path%3A%2F%5Eclang%5C%2Ftest%5C%2FCIR%5C%2F%2F&type=code

I'm happy to clean those up as well if you'd like. Or, if this cleanup isn't necessary right now, I just close this PR.

@erichkeane

Copy link
Copy Markdown
Contributor

I've reverted the CK_VectorSplat patch. The PR is now scoped solely to cleaning up the test by using -verify.

I noticed there are other tests in clang/test/CIR still relying on the 2>&1 redirection pattern: https://github.com/search?q=repo%3Allvm%2Fllvm-project+%222%3E%261%22+path%3A%2F%5Eclang%5C%2Ftest%5C%2FCIR%5C%2F%2F&type=code

I'm happy to clean those up as well if you'd like. Or, if this cleanup isn't necessary right now, I just close this PR.

There is likely value in cleaning those up as well.

@Men-cotton
Men-cotton merged commit d72e95b into llvm:main Feb 28, 2026
10 checks passed
@Men-cotton
Men-cotton deleted the Men-cotton/matrix-element-expr-load branch February 28, 2026 04:12
sahas3 pushed a commit to sahas3/llvm-project that referenced this pull request Mar 4, 2026
…-load.hlsl (llvm#182817)

Update clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl to use
`-verify` with expected CIR NYI diagnostics.
sujianIBM pushed a commit to sujianIBM/llvm-project that referenced this pull request Mar 5, 2026
…-load.hlsl (llvm#182817)

Update clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl to use
`-verify` with expected CIR NYI diagnostics.
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.

6 participants