[cfe-dev] Optimization of arithmetic expressions involving user-defined C++ objects

ardi via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 14 05:18:51 PDT 2020


Hi!

AFAIK, there's no C++ syntax for letting know the compiler that the
operators in your classes exactly match the same meaning as some
built-in type. So, if for example you write a class that implements
IEEE fp math in software, the compiler won't have the chance of
transforming the expression into a different one that has the same
result with a lower computation cost (*).

Given that LLVM is hackable by nature, is there some workaround by
which I could tell clang "consider the operators for this class with
the same optimization opportunities as this other built-in type" ?

Alternatively, does LLVM have any tool (or do you know of any outside
LLVM) that would allow to perform static optimization of an arithmetic
expression and transform the code, similar to a preprocessor step?

(*) Note: I acknowledge that even if the operators had the same
meaning as a built-in type, maybe their relative cost would be
different, so, ideally it wouldn't be a matter of just telling the
meaning of the operator, but also its relative cost.


Thanks a lot,

ardi


More information about the cfe-dev mailing list