AnyDSL / thorin2

The Higher ORder INtermediate representation - next gen
https://anydsl.github.io/thorin2/
MIT License
46 stars 9 forks source link

Specialize (.Idx, .Idx)#cond to generate a select instruction. #239

Closed fodinabor closed 1 year ago

fodinabor commented 1 year ago

Currently, we would generate an array, store that, calculate the offset with a GEP and then load from the GEP. LLVM does an awful job optimizing this (potentially due to missing alias info or so). That's why I initially resorted to actually using if/else in the regex impl, but that is also not optimized too neatly. Therefore, I added a specialization for 2-element integral tuples (yeah, should work for a bunch of other types as well), to emit a select instruction instead.

On the regex benchmark, this gives a performance upgrade of ~14% speedup, leaving only a 13% slowdown compared to the manual version. Old:

engine,average[us],min[us],max[us],deviation[%],
thorin,1119,1103,1150,4,
manual,861,839,891,6,

New:

engine,average[us],min[us],max[us],deviation[%],runs[us]
thorin,974,949,1009,6,
manual,857,835,894,6,