0

I have written a simple nested macro in LLL, but I can't get it to reduce to the simplest expression when calling the compiler with the optimization option. My macro looks like this:

(def 'mcopy (pos loc length) (codecopy (sub (mul pos 0x2) length) loc length))

Reading the LLL compiler documentation, it seems as though invocation of the above with constants should produce a reduced assembly expression with constants, like codecopy(x, b, c), and not codecopy(sub(mul(a, 0x2), c), b, c) as I see in the disassembled bytecode. I've read elsewhere that not all optimizations are guaranteed to occur, but I was wondering if there was a simple way to fix this, aside from writing my own preprocessor on the .lll source code.

0

It's true that the optimiser is sometimes not as effective on LLL code as on Solidity, but in this case I'm seeing a good effect from the constant expression folding:

> lllc --version
LLLC, the Lovely Little Language Compiler
Version: 0.4.20-develop.2017.12.5+commit.4cad0b22.Linux.g++

> cat optimiser_0.lll 
(seq
  (def 'mcopy (pos loc length) (codecopy (sub (mul pos 0x2) length) loc length))
  (mcopy 0x10 0x02 0x03))

> lllc -a optimiser_0.lll 
  codecopy(sub(mul(0x10, 0x2), 0x3), 0x2, 0x3)

> lllc -a -o optimiser_0.lll 
  codecopy(0x1d, 0x2, 0x3)

Now, this is as simple a context as possible, and your context will be more complex. This may impede the optimiser. If you can provide a minimum example that the optimiser fails to handle I'll take a look.

1
  • You're right. I realized that I was using the American English "optimize" as a flag, and it was failing silently. It works in my context too now. Dec 5 '17 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.