Skip to content

Conversation

@metkarpoonam
Copy link
Contributor

No description provided.

@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:headers Headers provided by Clang, e.g. for intrinsics HLSL HLSL Language Support labels Feb 19, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 19, 2025

@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-clang

Author: None (metkarpoonam)

Changes

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

3 Files Affected:

  • (modified) clang/include/clang/Basic/Builtins.td (+7-1)
  • (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+19)
  • (modified) clang/lib/Sema/SemaHLSL.cpp (+23)
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index 29939242596ba..d71d17d9e3e01 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -98,7 +98,7 @@ def AcoshF128 : Builtin {
 }
 
 def AsinF16F128 : Builtin, F16F128MathTemplate {
-  let Spellings = ["__builtin_asin"];
+  let Spellings = ["__builtin_asin"];   
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow,
                     ConstIgnoringErrnoAndExceptions];
   let Prototype = "T(T)";
@@ -1238,6 +1238,7 @@ def NondetermenisticValue : Builtin {
   let Prototype = "void(...)";
 }
 
+
 def ElementwiseAbs : Builtin {
   let Spellings = ["__builtin_elementwise_abs"];
   let Attributes = [NoThrow, Const, CustomTypeChecking];
@@ -4968,6 +4969,11 @@ def HLSLGroupMemoryBarrierWithGroupSync: LangBuiltin<"HLSL_LANG"> {
   let Attributes = [NoThrow, Const];
   let Prototype = "void()";
 }
+def HLSLOr : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_or"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
 
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d1f5fdff8b600..a3238c806262b 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -37,6 +37,25 @@ namespace hlsl {
 #define _HLSL_16BIT_AVAILABILITY_STAGE(environment, version, stage)
 #endif
 
+//===----------------------------------------------------------------------===//
+// or builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn T or(T x, T y)
+/// \brief Returns the bitwise OR of the two input values, \a x and \a y.
+/// \param x The first input value and y The second input value.
+/// 
+/// \returns The bitwise OR of the two input values.
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool or (bool, bool);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool2 or (bool2, bool2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool3 or (bool3, bool3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool4 or (bool4, bool4);
+
 //===----------------------------------------------------------------------===//
 // abs builtins
 //===----------------------------------------------------------------------===//
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 4abd870ad6aaa..28e121ae2b8cb 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2558,6 +2558,29 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
     }
     break;
   }
+
+    case Builtin::BI__builtin_hlsl_or: {
+      if (SemaRef.checkArgCount(TheCall, 2))
+        return true;
+     if (CheckVectorElementCallArgs(&SemaRef, TheCall))
+       return true;
+
+    //Ensure input parameter type is bool
+     ExprResult A = TheCall->getArg(0);
+     QualType ArgTyA = A.get()->getType();
+     ExprResult B = TheCall->getArg(1);
+     QualType ArgTyB = B.get()->getType();
+     if (!ArgTyA->isBooleanType() || !ArgTyB->isBooleanType()) {
+       SemaRef.Diag(TheCall->getArg(0)->getBeginLoc(),
+                    diag::err_typecheck_convert_incompatible)
+           << ArgTyA << SemaRef.Context.BoolTy << 1 << 0 << 0;
+       return true;
+     }
+    // Ensure input expr type is a scalar/vector and the same as the return type
+     if (CheckAnyScalarOrVector(&SemaRef, TheCall, 0))
+       return true;
+     break;
+   }
   }
   return false;
 }

@llvmbot
Copy link
Member

llvmbot commented Feb 19, 2025

@llvm/pr-subscribers-backend-x86

Author: None (metkarpoonam)

Changes

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

3 Files Affected:

  • (modified) clang/include/clang/Basic/Builtins.td (+7-1)
  • (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+19)
  • (modified) clang/lib/Sema/SemaHLSL.cpp (+23)
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index 29939242596ba..d71d17d9e3e01 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -98,7 +98,7 @@ def AcoshF128 : Builtin {
 }
 
 def AsinF16F128 : Builtin, F16F128MathTemplate {
-  let Spellings = ["__builtin_asin"];
+  let Spellings = ["__builtin_asin"];   
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow,
                     ConstIgnoringErrnoAndExceptions];
   let Prototype = "T(T)";
@@ -1238,6 +1238,7 @@ def NondetermenisticValue : Builtin {
   let Prototype = "void(...)";
 }
 
+
 def ElementwiseAbs : Builtin {
   let Spellings = ["__builtin_elementwise_abs"];
   let Attributes = [NoThrow, Const, CustomTypeChecking];
@@ -4968,6 +4969,11 @@ def HLSLGroupMemoryBarrierWithGroupSync: LangBuiltin<"HLSL_LANG"> {
   let Attributes = [NoThrow, Const];
   let Prototype = "void()";
 }
+def HLSLOr : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_or"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
 
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d1f5fdff8b600..a3238c806262b 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -37,6 +37,25 @@ namespace hlsl {
 #define _HLSL_16BIT_AVAILABILITY_STAGE(environment, version, stage)
 #endif
 
+//===----------------------------------------------------------------------===//
+// or builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn T or(T x, T y)
+/// \brief Returns the bitwise OR of the two input values, \a x and \a y.
+/// \param x The first input value and y The second input value.
+/// 
+/// \returns The bitwise OR of the two input values.
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool or (bool, bool);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool2 or (bool2, bool2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool3 or (bool3, bool3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool4 or (bool4, bool4);
+
 //===----------------------------------------------------------------------===//
 // abs builtins
 //===----------------------------------------------------------------------===//
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 4abd870ad6aaa..28e121ae2b8cb 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2558,6 +2558,29 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
     }
     break;
   }
+
+    case Builtin::BI__builtin_hlsl_or: {
+      if (SemaRef.checkArgCount(TheCall, 2))
+        return true;
+     if (CheckVectorElementCallArgs(&SemaRef, TheCall))
+       return true;
+
+    //Ensure input parameter type is bool
+     ExprResult A = TheCall->getArg(0);
+     QualType ArgTyA = A.get()->getType();
+     ExprResult B = TheCall->getArg(1);
+     QualType ArgTyB = B.get()->getType();
+     if (!ArgTyA->isBooleanType() || !ArgTyB->isBooleanType()) {
+       SemaRef.Diag(TheCall->getArg(0)->getBeginLoc(),
+                    diag::err_typecheck_convert_incompatible)
+           << ArgTyA << SemaRef.Context.BoolTy << 1 << 0 << 0;
+       return true;
+     }
+    // Ensure input expr type is a scalar/vector and the same as the return type
+     if (CheckAnyScalarOrVector(&SemaRef, TheCall, 0))
+       return true;
+     break;
+   }
   }
   return false;
 }

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

Labels

backend:X86 clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:headers Headers provided by Clang, e.g. for intrinsics clang Clang issues not falling into any other category HLSL HLSL Language Support

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants