Need help: How to turn off the constant folding optimization in llvm

Usually when someone talks about “constant folding optimization” they mean an LLVM pass that operates on the IR to combine constants in operations that had been expressed as instructions in the IR.

I think what you are looking at is a constant-expression evaluation that is done before any IR is generated; in effect, it is being performed by the parser, not the optimizer. I’m not aware of a command-line option to turn this off, although there might be one.

If you just want to look at simple examples of IR, you could do this instead:

int y = 2;

y *= 4;

and this will produce a ‘mul’ instruction.

–paulr

image002.png