This PR introduce cir simplification pass. The idea is to have a pass for the redundant operations removal/update.
Right now two pattern implemented, both related to the redundant bool operations.
First pattern removes redundant casts from bool to int and back that for some reasons appear in the code.
Second pattern removes sequential unary not operations (!!) .
For example, the code from the test is expanded from the simple check that is common for C code:
#define CHECK_PTR(ptr) \
do { \
if (__builtin_expect((!!((ptr) == 0)), 0))\
return -42; \
} while(0)
I mark this PR as a draft for the following reasons:
1) I have no idea if it's useful for the community
2) There is a test fail - unfortunately current pattern rewriter run DCE underneath the hood and looks like we can't workaround it.
It's enough just to add an operation to the list - in this case UnaryOp - and call applyOpPatternsAndFold. I could rewrite a test a little in order to make everything non dead or implement a simple fix point algorithm for the particular task (I would do the former).
This PR introduce cir simplification pass. The idea is to have a pass for the redundant operations removal/update.
Right now two pattern implemented, both related to the redundant
bool
operations. First pattern removes redundant casts frombool
toint
and back that for some reasons appear in the code. Second pattern removes sequential unary not operations (!!
) .For example, the code from the test is expanded from the simple check that is common for C code:
I mark this PR as a draft for the following reasons: 1) I have no idea if it's useful for the community 2) There is a test fail - unfortunately current pattern rewriter run DCE underneath the hood and looks like we can't workaround it. It's enough just to add an operation to the list - in this case
UnaryOp
- and callapplyOpPatternsAndFold
. I could rewrite a test a little in order to make everything non dead or implement a simple fix point algorithm for the particular task (I would do the former).