[PATCH] D156223: [RISCV] Resolve a few bugs in RISCVVIntrinsicUtils.cpp

2023-08-03 Thread Brandon Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf3ce925083d2: [RISCV] Resolve a few bugs in 
RISCVVIntrinsicUtils.cpp (authored by 4vtomat).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156223/new/

https://reviews.llvm.org/D156223

Files:
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/lib/Support/RISCVVIntrinsicUtils.cpp
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v_invalid.c


Index: 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v_invalid.c
===
--- /dev/null
+++ 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v_invalid.c
@@ -0,0 +1,21 @@
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -target-feature +zfh \
+// RUN:   -target-feature +zvfh -disable-O0-optnone %s -fsyntax-only -verify
+
+#include 
+
+vuint64m2_t test_vlmul_trunc_v_u64m2_u64m2(vuint64m2_t op1) { // expected-note 
{{'test_vlmul_trunc_v_u64m2_u64m2' declared here}}
+  return __riscv_vlmul_trunc_v_u64m2_u64m2(op1); // expected-error {{call to 
undeclared function '__riscv_vlmul_trunc_v_u64m2_u64m2'; ISO C99 and later do 
not support implicit function declarations}} expected-error {{returning 'int' 
from a function with incompatible result type 'vuint64m2_t' (aka 
'__rvv_uint64m2_t')}} expected-note {{did you mean 
'test_vlmul_trunc_v_u64m2_u64m2'?}}
+}
+
+vuint64m4_t test_vlmul_trunc_v_u64m4_u64m4(vuint64m4_t op1) { // expected-note 
{{'test_vlmul_trunc_v_u64m4_u64m4' declared here}}
+  return __riscv_vlmul_trunc_v_u64m4_u64m4(op1); // expected-error {{call to 
undeclared function '__riscv_vlmul_trunc_v_u64m4_u64m4'; ISO C99 and later do 
not support implicit function declarations}} expected-error {{returning 'int' 
from a function with incompatible result type 'vuint64m4_t' (aka 
'__rvv_uint64m4_t')}} expected-note {{did you mean 
'test_vlmul_trunc_v_u64m4_u64m4'?}}
+}
+
+vuint64m1_t test_vlmul_trunc_v_u64m1_u64m1(vuint64m1_t op1) { // expected-note 
{{'test_vlmul_trunc_v_u64m1_u64m1' declared here}}
+  return __riscv_vlmul_trunc_v_u64m1_u64m1(op1); // expected-error {{call to 
undeclared function '__riscv_vlmul_trunc_v_u64m1_u64m1'; ISO C99 and later do 
not support implicit function declarations}} expected-error {{returning 'int' 
from a function with incompatible result type 'vuint64m1_t' (aka 
'__rvv_uint64m1_t')}} expected-note {{did you mean 
'test_vlmul_trunc_v_u64m1_u64m1'?}}
+}
+
+vuint64m8_t test_vlmul_trunc_v_u64m8_u64m8(vuint64m8_t op1) { // expected-note 
{{'test_vlmul_trunc_v_u64m8_u64m8' declared here}}
+  return __riscv_vlmul_trunc_v_u64m8_u64m8(op1); // expected-error {{call to 
undeclared function '__riscv_vlmul_trunc_v_u64m8_u64m8'; ISO C99 and later do 
not support implicit function declarations}} expected-error {{returning 'int' 
from a function with incompatible result type 'vuint64m8_t' (aka 
'__rvv_uint64m8_t')}} expected-note {{did you mean 
'test_vlmul_trunc_v_u64m8_u64m8'?}}
+}
Index: clang/lib/Support/RISCVVIntrinsicUtils.cpp
===
--- clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -742,6 +742,10 @@
 break;
   }
 
+  // Early return if the current type modifier is already invalid.
+  if (ScalarType == Invalid)
+return;
+
   for (unsigned TypeModifierMaskShift = 0;
TypeModifierMaskShift <= static_cast(TypeModifier::MaxOffset);
++TypeModifierMaskShift) {
@@ -803,13 +807,13 @@
 void RVVType::applyFixedLog2LMUL(int Log2LMUL, enum FixedLMULType Type) {
   switch (Type) {
   case FixedLMULType::LargerThan:
-if (Log2LMUL < LMUL.Log2LMUL) {
+if (Log2LMUL <= LMUL.Log2LMUL) {
   ScalarType = ScalarTypeKind::Invalid;
   return;
 }
 break;
   case FixedLMULType::SmallerThan:
-if (Log2LMUL > LMUL.Log2LMUL) {
+if (Log2LMUL >= LMUL.Log2LMUL) {
   ScalarType = ScalarTypeKind::Invalid;
   return;
 }
Index: clang/lib/Sema/SemaRISCVVectorLookup.cpp
===
--- clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -133,6 +133,7 @@
 }
 break;
   case Invalid:
+  case Undefined:
 llvm_unreachable("Unhandled type.");
   }
   if (Type->isVector()) {
Index: clang/include/clang/Support/RISCVVIntrinsicUtils.h
===
--- clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -218,6 +218,7 @@
   UnsignedInteger,
   Float,
   Invalid,
+  Undefined,
 };
 
 // Exponential LMUL
@@ -240,7 +241,7 @@
   

[PATCH] D156223: [RISCV] Resolve a few bugs in RISCVVIntrinsicUtils.cpp

2023-08-03 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng accepted this revision.
kito-cheng added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/Sema/SemaRISCVVectorLookup.cpp:136
   case Invalid:
+  case Undefined:
 llvm_unreachable("Unhandled type.");

4vtomat wrote:
> eopXD wrote:
> > Could we just reuse `Invalid`?
> We can't reuse Invalid, since `ScalarType` in `RVVType` class is default to 
> `Invalid`, we are not able to determine whether it's really invalid or not 
> during `applyModifier` function, so that's the reason why I added `Undefined` 
> to differentiate between `default` and `really invalid`.
I has some question before too :P thanks for explanation!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156223/new/

https://reviews.llvm.org/D156223

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156223: [RISCV] Resolve a few bugs in RISCVVIntrinsicUtils.cpp

2023-07-26 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat added inline comments.



Comment at: clang/lib/Sema/SemaRISCVVectorLookup.cpp:136
   case Invalid:
+  case Undefined:
 llvm_unreachable("Unhandled type.");

eopXD wrote:
> Could we just reuse `Invalid`?
We can't reuse Invalid, since `ScalarType` in `RVVType` class is default to 
`Invalid`, we are not able to determine whether it's really invalid or not 
during `applyModifier` function, so that's the reason why I added `Undefined` 
to differentiate between `default` and `really invalid`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156223/new/

https://reviews.llvm.org/D156223

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156223: [RISCV] Resolve a few bugs in RISCVVIntrinsicUtils.cpp

2023-07-26 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat updated this revision to Diff 544254.
4vtomat added a comment.

Add a test case for invalid example.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156223/new/

https://reviews.llvm.org/D156223

Files:
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/lib/Support/RISCVVIntrinsicUtils.cpp
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v_invalid.c


Index: 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v_invalid.c
===
--- /dev/null
+++ 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v_invalid.c
@@ -0,0 +1,21 @@
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -target-feature +zfh \
+// RUN:   -target-feature +zvfh -disable-O0-optnone %s -fsyntax-only -verify
+
+#include 
+
+vuint64m2_t test_vlmul_trunc_v_u64m2_u64m2(vuint64m2_t op1) { // expected-note 
{{'test_vlmul_trunc_v_u64m2_u64m2' declared here}}
+  return __riscv_vlmul_trunc_v_u64m2_u64m2(op1); // expected-error {{call to 
undeclared function '__riscv_vlmul_trunc_v_u64m2_u64m2'; ISO C99 and later do 
not support implicit function declarations}} expected-error {{returning 'int' 
from a function with incompatible result type 'vuint64m2_t' (aka 
'__rvv_uint64m2_t')}} expected-note {{did you mean 
'test_vlmul_trunc_v_u64m2_u64m2'?}}
+}
+
+vuint64m4_t test_vlmul_trunc_v_u64m4_u64m4(vuint64m4_t op1) { // expected-note 
{{'test_vlmul_trunc_v_u64m4_u64m4' declared here}}
+  return __riscv_vlmul_trunc_v_u64m4_u64m4(op1); // expected-error {{call to 
undeclared function '__riscv_vlmul_trunc_v_u64m4_u64m4'; ISO C99 and later do 
not support implicit function declarations}} expected-error {{returning 'int' 
from a function with incompatible result type 'vuint64m4_t' (aka 
'__rvv_uint64m4_t')}} expected-note {{did you mean 
'test_vlmul_trunc_v_u64m4_u64m4'?}}
+}
+
+vuint64m1_t test_vlmul_trunc_v_u64m1_u64m1(vuint64m1_t op1) { // expected-note 
{{'test_vlmul_trunc_v_u64m1_u64m1' declared here}}
+  return __riscv_vlmul_trunc_v_u64m1_u64m1(op1); // expected-error {{call to 
undeclared function '__riscv_vlmul_trunc_v_u64m1_u64m1'; ISO C99 and later do 
not support implicit function declarations}} expected-error {{returning 'int' 
from a function with incompatible result type 'vuint64m1_t' (aka 
'__rvv_uint64m1_t')}} expected-note {{did you mean 
'test_vlmul_trunc_v_u64m1_u64m1'?}}
+}
+
+vuint64m8_t test_vlmul_trunc_v_u64m8_u64m8(vuint64m8_t op1) { // expected-note 
{{'test_vlmul_trunc_v_u64m8_u64m8' declared here}}
+  return __riscv_vlmul_trunc_v_u64m8_u64m8(op1); // expected-error {{call to 
undeclared function '__riscv_vlmul_trunc_v_u64m8_u64m8'; ISO C99 and later do 
not support implicit function declarations}} expected-error {{returning 'int' 
from a function with incompatible result type 'vuint64m8_t' (aka 
'__rvv_uint64m8_t')}} expected-note {{did you mean 
'test_vlmul_trunc_v_u64m8_u64m8'?}}
+}
Index: clang/lib/Support/RISCVVIntrinsicUtils.cpp
===
--- clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -742,6 +742,10 @@
 break;
   }
 
+  // Early return if the current type modifier is already invalid.
+  if (ScalarType == Invalid)
+return;
+
   for (unsigned TypeModifierMaskShift = 0;
TypeModifierMaskShift <= static_cast(TypeModifier::MaxOffset);
++TypeModifierMaskShift) {
@@ -803,13 +807,13 @@
 void RVVType::applyFixedLog2LMUL(int Log2LMUL, enum FixedLMULType Type) {
   switch (Type) {
   case FixedLMULType::LargerThan:
-if (Log2LMUL < LMUL.Log2LMUL) {
+if (Log2LMUL <= LMUL.Log2LMUL) {
   ScalarType = ScalarTypeKind::Invalid;
   return;
 }
 break;
   case FixedLMULType::SmallerThan:
-if (Log2LMUL > LMUL.Log2LMUL) {
+if (Log2LMUL >= LMUL.Log2LMUL) {
   ScalarType = ScalarTypeKind::Invalid;
   return;
 }
Index: clang/lib/Sema/SemaRISCVVectorLookup.cpp
===
--- clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -133,6 +133,7 @@
 }
 break;
   case Invalid:
+  case Undefined:
 llvm_unreachable("Unhandled type.");
   }
   if (Type->isVector()) {
Index: clang/include/clang/Support/RISCVVIntrinsicUtils.h
===
--- clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -218,6 +218,7 @@
   UnsignedInteger,
   Float,
   Invalid,
+  Undefined,
 };
 
 // Exponential LMUL
@@ -240,7 +241,7 @@
   friend class RVVTypeCache;
 
   BasicType BT;
-  ScalarTypeKind ScalarType = Invalid;
+  ScalarTypeKind ScalarType = Undefined;
   

[PATCH] D156223: [RISCV] Resolve a few bugs in RISCVVIntrinsicUtils.cpp

2023-07-26 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD added inline comments.



Comment at: clang/lib/Sema/SemaRISCVVectorLookup.cpp:136
   case Invalid:
+  case Undefined:
 llvm_unreachable("Unhandled type.");

Could we just reuse `Invalid`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156223/new/

https://reviews.llvm.org/D156223

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156223: [RISCV] Resolve a few bugs in RISCVVIntrinsicUtils.cpp

2023-07-25 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

Does it possible to add a precommit test case to show that we accept unexpected 
combination of the type?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156223/new/

https://reviews.llvm.org/D156223

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156223: [RISCV] Resolve a few bugs in RISCVVIntrinsicUtils.cpp

2023-07-25 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat created this revision.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, 
arichardson.
Herald added a project: All.
4vtomat requested review of this revision.
Herald added subscribers: cfe-commits, wangpc, eopXD, MaskRay.
Herald added a project: clang.

This patch does a few things:

1. Add a new type called Undefined to ScalarTypeKind.
2. Make RVVType::applyModifier early return when encounter invalid ScalarType, 
otherwise it could be modified to "non-invalid" type in the following code.
3. When FixedLMULType::SmallerThan is applied, the lmul should be "<" than 
specified one, so lmuls which are ">=" should be marked as invalid.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156223

Files:
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/lib/Support/RISCVVIntrinsicUtils.cpp


Index: clang/lib/Support/RISCVVIntrinsicUtils.cpp
===
--- clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -742,6 +742,10 @@
 break;
   }
 
+  // Early return if the current type modifier is already invalid.
+  if (ScalarType == Invalid)
+return;
+
   for (unsigned TypeModifierMaskShift = 0;
TypeModifierMaskShift <= static_cast(TypeModifier::MaxOffset);
++TypeModifierMaskShift) {
@@ -803,13 +807,13 @@
 void RVVType::applyFixedLog2LMUL(int Log2LMUL, enum FixedLMULType Type) {
   switch (Type) {
   case FixedLMULType::LargerThan:
-if (Log2LMUL < LMUL.Log2LMUL) {
+if (Log2LMUL <= LMUL.Log2LMUL) {
   ScalarType = ScalarTypeKind::Invalid;
   return;
 }
 break;
   case FixedLMULType::SmallerThan:
-if (Log2LMUL > LMUL.Log2LMUL) {
+if (Log2LMUL >= LMUL.Log2LMUL) {
   ScalarType = ScalarTypeKind::Invalid;
   return;
 }
Index: clang/lib/Sema/SemaRISCVVectorLookup.cpp
===
--- clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -133,6 +133,7 @@
 }
 break;
   case Invalid:
+  case Undefined:
 llvm_unreachable("Unhandled type.");
   }
   if (Type->isVector()) {
Index: clang/include/clang/Support/RISCVVIntrinsicUtils.h
===
--- clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -218,6 +218,7 @@
   UnsignedInteger,
   Float,
   Invalid,
+  Undefined,
 };
 
 // Exponential LMUL
@@ -240,7 +241,7 @@
   friend class RVVTypeCache;
 
   BasicType BT;
-  ScalarTypeKind ScalarType = Invalid;
+  ScalarTypeKind ScalarType = Undefined;
   LMULType LMUL;
   bool IsPointer = false;
   // IsConstant indices are "int", but have the constant expression.


Index: clang/lib/Support/RISCVVIntrinsicUtils.cpp
===
--- clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -742,6 +742,10 @@
 break;
   }
 
+  // Early return if the current type modifier is already invalid.
+  if (ScalarType == Invalid)
+return;
+
   for (unsigned TypeModifierMaskShift = 0;
TypeModifierMaskShift <= static_cast(TypeModifier::MaxOffset);
++TypeModifierMaskShift) {
@@ -803,13 +807,13 @@
 void RVVType::applyFixedLog2LMUL(int Log2LMUL, enum FixedLMULType Type) {
   switch (Type) {
   case FixedLMULType::LargerThan:
-if (Log2LMUL < LMUL.Log2LMUL) {
+if (Log2LMUL <= LMUL.Log2LMUL) {
   ScalarType = ScalarTypeKind::Invalid;
   return;
 }
 break;
   case FixedLMULType::SmallerThan:
-if (Log2LMUL > LMUL.Log2LMUL) {
+if (Log2LMUL >= LMUL.Log2LMUL) {
   ScalarType = ScalarTypeKind::Invalid;
   return;
 }
Index: clang/lib/Sema/SemaRISCVVectorLookup.cpp
===
--- clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -133,6 +133,7 @@
 }
 break;
   case Invalid:
+  case Undefined:
 llvm_unreachable("Unhandled type.");
   }
   if (Type->isVector()) {
Index: clang/include/clang/Support/RISCVVIntrinsicUtils.h
===
--- clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -218,6 +218,7 @@
   UnsignedInteger,
   Float,
   Invalid,
+  Undefined,
 };
 
 // Exponential LMUL
@@ -240,7 +241,7 @@
   friend class RVVTypeCache;
 
   BasicType BT;
-  ScalarTypeKind ScalarType = Invalid;
+  ScalarTypeKind ScalarType = Undefined;
   LMULType LMUL;
   bool IsPointer = false;
   // IsConstant