Skip to content

Commit 7a08d1f

Browse files
committed
Add canonicalization
1 parent 20d70fc commit 7a08d1f

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,7 @@ def SPIRV_GLLengthOp : SPIRV_GLOp<"Length", 66, [
11961196
}];
11971197

11981198
let hasVerifier = 0;
1199+
let hasCanonicalizer = 1;
11991200
}
12001201

12011202
// -----

mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,3 +1403,12 @@ void spirv::SelectionOp::getCanonicalizationPatterns(RewritePatternSet &results,
14031403
MLIRContext *context) {
14041404
results.add<ConvertSelectionOpToSelect>(context);
14051405
}
1406+
1407+
//===----------------------------------------------------------------------===//
1408+
// spirv.GL.Length
1409+
//===----------------------------------------------------------------------===//
1410+
1411+
void spirv::GLLengthOp::getCanonicalizationPatterns(RewritePatternSet &results,
1412+
MLIRContext *context) {
1413+
results.add<ConvertGLLengthToGLFAbs>(context);
1414+
}

mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,11 @@ def ConvertComparisonIntoClamp2_#CmpClampPair[0] : Pat<
7575
)),
7676
(CmpClampPair[1] $input, $min, $max)>;
7777
}
78+
79+
//===----------------------------------------------------------------------===//
80+
// spirv.GL.Length -> spirv.GL.FAbs
81+
//===----------------------------------------------------------------------===//
82+
83+
def ConvertGLLengthToGLFAbs : Pat<
84+
(SPIRV_GLLengthOp SPIRV_Float:$operand),
85+
(SPIRV_GLFAbsOp $operand)>;

mlir/test/Dialect/SPIRV/Transforms/canonicalize.mlir

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,3 +2490,24 @@ func.func @cannot_canonicalize_selection_op_4(%cond: i1) -> () {
24902490
}
24912491
spirv.Return
24922492
}
2493+
2494+
// -----
2495+
2496+
//===----------------------------------------------------------------------===//
2497+
// spirv.GL.Length
2498+
//===----------------------------------------------------------------------===//
2499+
2500+
// CHECK-LABEL: @convert_length_into_fabs_scalar
2501+
func.func @convert_length_in_fabs_scalar(%arg0 : f32) -> f32 {
2502+
2503+
%0 = spirv.GL.Length %arg0 : f32 -> f32
2504+
//%11 = spirv.GL.Length %arg1 : vector<3xf32> -> f32
2505+
spirv.ReturnValue %0 : f32
2506+
}
2507+
2508+
// CHECK-LABEL: @dont_convert_length_into_fabs_vec
2509+
func.func @dont_convert_length_in_fabs_vec(%arg0 : vector<3xf32>) -> f32 {
2510+
2511+
%0 = spirv.GL.Length %arg0 : vector<3xf32> -> f32
2512+
spirv.ReturnValue %0 : f32
2513+
}

0 commit comments

Comments
 (0)