This patch simplifies the cmpi Standard dialect operation when its operands are identical and it replaces it with a constant representing the outcome of the comparison.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
mlir/lib/Dialect/StandardOps/IR/Ops.cpp | ||
---|---|---|
883 | This looks like it should be part of the fold method instead. | |
892 | Can you use proper operand accessors instead of this? (.lhs()/.rhs()) | |
mlir/test/Dialect/Standard/canonicalize.mlir | ||
14 | Please avoid the use of SSA value names inside of check lines, use captures instead. |
mlir/lib/Dialect/StandardOps/IR/Ops.cpp | ||
---|---|---|
883 | I tried that but it led to many lit test failures. I think the problem is that the input to fold are attributes whereas here I have Value operands. |
mlir/lib/Dialect/StandardOps/IR/Ops.cpp | ||
---|---|---|
883 | The input attributes to fold are operands that are known to be constant, i.e. you can still use the operands directly from the operation. If you are getting lit failures, that is due to something else. (e.g. tests being broken by better folding that changed the expected output) |
mlir/lib/Dialect/StandardOps/IR/Ops.cpp | ||
---|---|---|
883 | Good point, I completely ignored the fact that I could get the operands as usual even when inside the fold function! It all works now. :) |
mlir/lib/Dialect/StandardOps/IR/Ops.cpp | ||
---|---|---|
860 | nit: Can you use BoolAttr::get here instead? BoolAttr is a utility wrapper around i1 IntegerAttr. | |
mlir/test/Dialect/Standard/canonicalize.mlir | ||
8 | Can you trim out all of the unnecessary operations here? You should be able to test these cases with just the cmpi and function arguments. | |
25 | Can you make sure to add tests for each of the other cases that you are folding? |
mlir/test/Dialect/Standard/canonicalize.mlir | ||
---|---|---|
3 | Do you need the select in any of these? Why not return the comparison result directly? |
Thanks. LGTM after resolving the last few comments.
mlir/lib/Dialect/StandardOps/IR/Ops.cpp | ||
---|---|---|
849 | This isn't possible, the operands to an operation are always valid. You only have to check null when accessing attributes from the operands parameter, as a null Attribute means that the operand isn't constant. | |
mlir/test/Dialect/Standard/canonicalize.mlir | ||
7 | nit: The general style is to have this before not after. | |
8 | nit: These CHECK-NOTS can be simplified to just CHECK-NOT: cmpi |
This isn't possible, the operands to an operation are always valid. You only have to check null when accessing attributes from the operands parameter, as a null Attribute means that the operand isn't constant.