reactorlabs / rir

GNU General Public License v2.0
62 stars 18 forks source link

Rewrite builder.CreateAnd and builder.CreateOr when translating to LLVM #1269

Open skrynski opened 7 months ago

skrynski commented 7 months ago

CreateAnd and CreateOr are used in such a way that both arguments are fully computed before the test is performed, reducing opportunity for short-circuiting.

Ex.


builder.CreateOr(
                builder.CreateICmpEQ(v, c(0)),   
                builder.CreateOr(builder.CreateICmpEQ(v, c(1)),
                                 builder.CreateICmpEQ(v, c(NA_LOGICAL))))

The way we write the code, both arguments to CreateOr will already emit code even before the method is invoked. Then the actual OR operation is emitted. I suggest we rewrite both operators similarly to what we do for createSelect2, this is, we take functions for the arguments. Going a step further, we could also take a vectors of functions instead of a fixed two args (see isVector())