llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)

<details>
<summary>Changes</summary>

Support lowering the constant vector of booleans as an element type

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


2 Files Affected:

- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+4-2) 
- (modified) clang/test/CIR/CodeGen/vector-bool.cpp (+11) 


``````````diff
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index ccdc974ca1b93..ec499301434e8 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -801,9 +801,11 @@ mlir::Value 
CIRAttrToValue::visitCirAttr(cir::ConstVectorAttr attr) {
     } else if (auto floatAttr = mlir::dyn_cast<cir::FPAttr>(elementAttr)) {
       mlirAttr = rewriter.getFloatAttr(
           converter->convertType(floatAttr.getType()), floatAttr.getValue());
+    } else if (auto boolAttr = mlir::dyn_cast<cir::BoolAttr>(elementAttr)) {
+      mlirAttr = rewriter.getBoolAttr(boolAttr.getValue());
     } else {
-      llvm_unreachable(
-          "vector constant with an element that is neither an int nor a 
float");
+      llvm_unreachable("vector constant with an element that is neither an "
+                       "int, a float, or a bool");
     }
     mlirValues.push_back(mlirAttr);
   }
diff --git a/clang/test/CIR/CodeGen/vector-bool.cpp 
b/clang/test/CIR/CodeGen/vector-bool.cpp
index 724d8109b048a..e01928b74f29c 100644
--- a/clang/test/CIR/CodeGen/vector-bool.cpp
+++ b/clang/test/CIR/CodeGen/vector-bool.cpp
@@ -7,6 +7,17 @@
 
 typedef bool v8b __attribute__((ext_vector_type(8)));
 
+void constant_vec_bool() {
+    v8b a = {true, false, true, false, true, false, true, false};
+}
+
+// CIR: %[[A_ADDR:.*]] = cir.alloca "a" {{.*}} init : !cir.ptr<!cir.vector<8 x 
!cir.bool>>
+// CIR: %[[CONST_VEC:.*]] = cir.const #cir.const_vector<[#true, #false, #true, 
#false, #true, #false, #true, #false]> : !cir.vector<8 x !cir.bool>
+// CIR: cir.store {{.*}} %[[CONST_VEC]], %[[A_ADDR]] : !cir.vector<8 x 
!cir.bool>, !cir.ptr<!cir.vector<8 x !cir.bool>>
+
+// LLVM: %[[A_ADDR:.*]] = alloca i8, align 1
+// LLVM: store i8 85, ptr %[[A_ADDR]], align 1
+
 void vec_bool_without_padding_needed() {
   v8b a;
   v8b b;

``````````

</details>


https://github.com/llvm/llvm-project/pull/216133
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to