[Mlir-commits] [mlir] [mlir][spirv] Add folding for [I|Logical][Not]Equal (PR #74194)
Jakub Kuderski
llvmlistbot at llvm.org
Wed Dec 6 14:58:54 PST 2023
================
@@ -309,19 +309,62 @@ OpFoldResult spirv::LogicalAndOp::fold(FoldAdaptor adaptor) {
return Attribute();
}
+//===----------------------------------------------------------------------===//
+// spirv.LogicalEqualOp
+//===----------------------------------------------------------------------===//
+
+OpFoldResult
+spirv::LogicalEqualOp::fold(spirv::LogicalEqualOp::FoldAdaptor adaptor) {
+ // x == x -> true
+ if (getOperand1() == getOperand2()) {
+ auto type = getType();
+ if (isa<IntegerType>(type)) {
+ return BoolAttr::get(getContext(), true);
+ }
+ if (isa<VectorType>(type)) {
+ auto vtType = cast<ShapedType>(type);
+ auto element = BoolAttr::get(getContext(), true);
+ return DenseElementsAttr::get(vtType, element);
+ }
----------------
kuhar wrote:
nit:
```suggestion
auto trueAttr = BoolAttr::get(getContext(), true);
if (isa<IntegerType>(getType())) {
return tureAttr;
}
if (auto vecTy = dyn_cast<VectorType>(getType())) {
return SplatElementsAttr::get(vecTy, tureAttr);
}
```
https://github.com/llvm/llvm-project/pull/74194
More information about the Mlir-commits
mailing list