-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[HLSL][Matrix] Add OR and AND logical operator support for matrix #172384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13389,6 +13389,25 @@ QualType Sema::CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, | |
| return GetSignedVectorType(LHS.get()->getType()); | ||
| } | ||
|
|
||
| QualType Sema::CheckMatrixLogicalOperands(ExprResult &LHS, ExprResult &RHS, | ||
| SourceLocation Loc, | ||
| BinaryOperatorKind Opc) { | ||
|
|
||
| if (!getLangOpts().HLSL) { | ||
| assert(false && "Logical operands are not support in C\\C++"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: supported |
||
| return QualType(); | ||
| } | ||
|
Comment on lines
+13396
to
+13399
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case is an assert where as the 2018 HLSL case is a Sema diagnostic error because its impossible today for C\C++ code to get into this function without explicit support for logical operators. The HLSL code really only exists to disable logical operators for the 2021 language mode. The 2018 language mode is suppose to support them but thats not our default language mode right now so that work will be punted on for now. |
||
|
|
||
| if (getLangOpts().getHLSLVersion() >= LangOptionsBase::HLSL_2021) { | ||
| (void)InvalidOperands(Loc, LHS, RHS); | ||
| HLSL().emitLogicalOperatorFixIt(LHS.get(), RHS.get(), Opc); | ||
| return QualType(); | ||
| } | ||
| SemaRef.Diag(LHS.get()->getBeginLoc(), diag::err_hlsl_langstd_unimplemented) | ||
| << getLangOpts().getHLSLVersion(); | ||
| return QualType(); | ||
| } | ||
|
|
||
| QualType Sema::CheckMatrixElementwiseOperands(ExprResult &LHS, ExprResult &RHS, | ||
| SourceLocation Loc, | ||
| bool IsCompAssign) { | ||
|
|
@@ -13561,6 +13580,10 @@ inline QualType Sema::CheckLogicalOperands(ExprResult &LHS, ExprResult &RHS, | |
| RHS.get()->getType()->isVectorType()) | ||
| return CheckVectorLogicalOperands(LHS, RHS, Loc, Opc); | ||
|
|
||
| if (LHS.get()->getType()->isConstantMatrixType() || | ||
| RHS.get()->getType()->isConstantMatrixType()) | ||
| return CheckMatrixLogicalOperands(LHS, RHS, Loc, Opc); | ||
|
|
||
| bool EnumConstantInBoolContext = false; | ||
| for (const ExprResult &HS : {LHS, RHS}) { | ||
| if (const auto *DREHS = dyn_cast<DeclRefExpr>(HS.get())) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,125 @@ | ||||||||||||||||||||||
| // RUN: %clang_cc1 -finclude-default-header -triple \ | ||||||||||||||||||||||
| // RUN: dxil-pc-shadermodel6.3-library %s \ | ||||||||||||||||||||||
| // RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| //CHECK-LABEL: define hidden noundef <2 x i1> @_Z16test_and_bool2x1u11matrix_typeILm2ELm1EbES_( | ||||||||||||||||||||||
| //CHECK-SAME: <2 x i1> noundef [[X:%.*]], <2 x i1> noundef [[Y:%.*]]) #[[ATTR0:[0-9]+]] { | ||||||||||||||||||||||
| //CHECK-NEXT: entry: | ||||||||||||||||||||||
| //CHECK: [[HLSL_AND:%.*]] = and <2 x i32> [[A:%.*]], [[B:%.*]] | ||||||||||||||||||||||
| //CHECK: ret <2 x i1> [[HLSL_AND_CAST:%.*]] | ||||||||||||||||||||||
|
Comment on lines
+5
to
+9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: there is no space between the
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same goes for the |
||||||||||||||||||||||
| bool2x1 test_and_bool2x1(bool2x1 x, bool2x1 y) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return and(x, y); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| //CHECK-LABEL: define hidden noundef <4 x i1> @_Z16test_and_bool2x2u11matrix_typeILm2ELm2EbES_( | ||||||||||||||||||||||
| //CHECK-SAME: <4 x i1> noundef [[X:%.*]], <4 x i1> noundef [[Y:%.*]]) #[[ATTR0]] { | ||||||||||||||||||||||
| //CHECK-NEXT: entry: | ||||||||||||||||||||||
| //CHECK: [[HLSL_AND:%.*]] = and <4 x i32> [[A:%.*]], [[B:%.*]] | ||||||||||||||||||||||
| //CHECK: ret <4 x i1> [[HLSL_AND_CAST:%.*]] | ||||||||||||||||||||||
| bool2x2 test_and_bool2x2(bool2x2 x, bool2x2 y) | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps add tests for 1xn matrices too. |
||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return and(x, y); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| //CHECK-LABEL: define hidden noundef <6 x i1> @_Z16test_and_bool2x3u11matrix_typeILm2ELm3EbES_( | ||||||||||||||||||||||
| //CHECK-SAME: <6 x i1> noundef [[X:%.*]], <6 x i1> noundef [[Y:%.*]]) #[[ATTR0]] { | ||||||||||||||||||||||
| //CHECK-NEXT: entry: | ||||||||||||||||||||||
| //CHECK: [[HLSL_AND:%.*]] = and <6 x i32> [[A:%.*]], [[B:%.*]] | ||||||||||||||||||||||
| //CHECK: ret <6 x i1> [[HLSL_AND_CAST:%.*]] | ||||||||||||||||||||||
| bool2x3 test_and_bool2x3(bool2x3 x, bool2x3 y) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return and(x, y); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| //CHECK-LABEL: define hidden noundef <8 x i1> @_Z16test_and_bool2x4u11matrix_typeILm2ELm4EbES_( | ||||||||||||||||||||||
| //CHECK-SAME: <8 x i1> noundef [[X:%.*]], <8 x i1> noundef [[Y:%.*]]) #[[ATTR0]] { | ||||||||||||||||||||||
| //CHECK-NEXT: entry: | ||||||||||||||||||||||
| //CHECK: [[HLSL_AND:%.*]] = and <8 x i32> [[A:%.*]], [[B:%.*]] | ||||||||||||||||||||||
| //CHECK: ret <8 x i1> [[HLSL_AND_CAST:%.*]] | ||||||||||||||||||||||
| bool2x4 test_and_bool2x4(bool2x4 x, bool2x4 y) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return and(x, y); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| //CHECK-LABEL: define hidden noundef <3 x i1> @_Z16test_and_bool3x1u11matrix_typeILm3ELm1EbES_( | ||||||||||||||||||||||
| //CHECK-SAME: <3 x i1> noundef [[X:%.*]], <3 x i1> noundef [[Y:%.*]]) #[[ATTR0]] { | ||||||||||||||||||||||
| //CHECK-NEXT: entry: | ||||||||||||||||||||||
| //CHECK: [[HLSL_AND:%.*]] = and <3 x i32> [[A:%.*]], [[B:%.*]] | ||||||||||||||||||||||
| //CHECK: ret <3 x i1> [[HLSL_AND_CAST:%.*]] | ||||||||||||||||||||||
| bool3x1 test_and_bool3x1(bool3x1 x, bool3x1 y) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return and(x, y); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| //CHECK-LABEL: define hidden noundef <6 x i1> @_Z16test_and_bool3x2u11matrix_typeILm3ELm2EbES_( | ||||||||||||||||||||||
| //CHECK-SAME: <6 x i1> noundef [[X:%.*]], <6 x i1> noundef [[Y:%.*]]) #[[ATTR0]] { | ||||||||||||||||||||||
| //CHECK-NEXT: entry: | ||||||||||||||||||||||
| //CHECK: [[HLSL_AND:%.*]] = and <6 x i32> [[A:%.*]], [[B:%.*]] | ||||||||||||||||||||||
| //CHECK: ret <6 x i1> [[HLSL_AND_CAST:%.*]] | ||||||||||||||||||||||
| bool3x2 test_and_bool3x2(bool3x2 x, bool3x2 y) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return and(x, y); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| //CHECK-LABEL: define hidden noundef <9 x i1> @_Z16test_and_bool3x3u11matrix_typeILm3ELm3EbES_( | ||||||||||||||||||||||
| //CHECK-SAME: <9 x i1> noundef [[X:%.*]], <9 x i1> noundef [[Y:%.*]]) #[[ATTR0]] { | ||||||||||||||||||||||
| //CHECK-NEXT: entry: | ||||||||||||||||||||||
| //CHECK: [[HLSL_AND:%.*]] = and <9 x i32> [[A:%.*]], [[B:%.*]] | ||||||||||||||||||||||
| //CHECK: ret <9 x i1> [[HLSL_AND_CAST:%.*]] | ||||||||||||||||||||||
| bool3x3 test_and_bool3x3(bool3x3 x, bool3x3 y) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return and(x, y); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| //CHECK-LABEL: define hidden noundef <12 x i1> @_Z16test_and_bool3x4u11matrix_typeILm3ELm4EbES_( | ||||||||||||||||||||||
| //CHECK-SAME: <12 x i1> noundef [[X:%.*]], <12 x i1> noundef [[Y:%.*]]) #[[ATTR0]] { | ||||||||||||||||||||||
| //CHECK-NEXT: entry: | ||||||||||||||||||||||
| //CHECK: [[HLSL_AND:%.*]] = and <12 x i32> [[A:%.*]], [[B:%.*]] | ||||||||||||||||||||||
| //CHECK: ret <12 x i1> [[HLSL_AND_CAST:%.*]] | ||||||||||||||||||||||
| bool3x4 test_and_bool3x4(bool3x4 x, bool3x4 y) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return and(x, y); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| //CHECK-LABEL: define hidden noundef <4 x i1> @_Z16test_and_bool4x1u11matrix_typeILm4ELm1EbES_( | ||||||||||||||||||||||
| //CHECK-SAME: <4 x i1> noundef [[X:%.*]], <4 x i1> noundef [[Y:%.*]]) #[[ATTR0]] { | ||||||||||||||||||||||
| //CHECK-NEXT: entry: | ||||||||||||||||||||||
| //CHECK: [[HLSL_AND:%.*]] = and <4 x i32> [[A:%.*]], [[B:%.*]] | ||||||||||||||||||||||
| //CHECK: ret <4 x i1> [[HLSL_AND_CAST:%.*]] | ||||||||||||||||||||||
| bool4x1 test_and_bool4x1(bool4x1 x, bool4x1 y) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return and(x, y); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| //CHECK-LABEL: define hidden noundef <8 x i1> @_Z16test_and_bool4x2u11matrix_typeILm4ELm2EbES_( | ||||||||||||||||||||||
| //CHECK-SAME: <8 x i1> noundef [[X:%.*]], <8 x i1> noundef [[Y:%.*]]) #[[ATTR0]] { | ||||||||||||||||||||||
| //CHECK-NEXT: entry: | ||||||||||||||||||||||
| //CHECK: [[HLSL_AND:%.*]] = and <8 x i32> [[A:%.*]], [[B:%.*]] | ||||||||||||||||||||||
| //CHECK: ret <8 x i1> [[HLSL_AND_CAST:%.*]] | ||||||||||||||||||||||
| bool4x2 test_and_bool4x2(bool4x2 x, bool4x2 y) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return and(x, y); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| //CHECK-LABEL: define hidden noundef <12 x i1> @_Z16test_and_bool4x3u11matrix_typeILm4ELm3EbES_( | ||||||||||||||||||||||
| //CHECK-SAME: <12 x i1> noundef [[X:%.*]], <12 x i1> noundef [[Y:%.*]]) #[[ATTR0]] { | ||||||||||||||||||||||
| //CHECK-NEXT: entry: | ||||||||||||||||||||||
| //CHECK: [[HLSL_AND:%.*]] = and <12 x i32> [[A:%.*]], [[B:%.*]] | ||||||||||||||||||||||
| //CHECK: ret <12 x i1> [[HLSL_AND_CAST:%.*]] | ||||||||||||||||||||||
| bool4x3 test_and_bool4x3(bool4x3 x, bool4x3 y) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return and(x, y); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| //CHECK-LABEL: define hidden noundef <16 x i1> @_Z16test_and_bool4x4u11matrix_typeILm4ELm4EbES_( | ||||||||||||||||||||||
| //CHECK-SAME: <16 x i1> noundef [[X:%.*]], <16 x i1> noundef [[Y:%.*]]) #[[ATTR0]] { | ||||||||||||||||||||||
| //CHECK-NEXT: entry: | ||||||||||||||||||||||
| //CHECK: [[HLSL_AND:%.*]] = and <16 x i32> [[A:%.*]], [[B:%.*]] | ||||||||||||||||||||||
| //CHECK: ret <16 x i1> [[HLSL_AND_CAST:%.*]] | ||||||||||||||||||||||
| bool4x4 test_and_bool4x4(bool4x4 x, bool4x4 y) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return and(x, y); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we include 1xn matrices here?