Long story short. I have some conversion routines and calls for these are generated by frontend. Is there any existing method to tell optimizer to remove opposite ones? Here is example what I have
Nah, I don’t think there’s any high level attributes on functions that’d provide that optimization - only interprocedural analysis that proves that they’re inverse of each other, etc.
You could inline it and rely on optimizations to identify they are opposing, but that would catch only simple cases. Also, if these were opposing llvm intrinsics (instead of regular function calls), instCombine would take care of it or you could add a rule.
When we had a similar problem for our usecase, it was something generated from the frontend and we taught the (downstream) optimizer that these were opposing abstractions.
You can add “a rule” for regular function calls just as well. We tend not to do that for things we cannot guarantee we know the semantic of, but we do match regular calls as well.