Inefficient code generation of @mod
and @divFloor
#19935
Labels
bug
Observed behavior contradicts documented or intended behavior
@mod
and @divFloor
#19935
Zig Version
0.12.0
Steps to Reproduce and Observed Behavior
When using signed integers and power of 2 denominators, the generated assembly contains a bunch of unnecessary instructions (Compiler Explorer)
Expected Behavior
A simple
and
orsar
(for@mod
or@divFloor
respectively) instruction would be enough in this case (Compiler Explorer). Note that the example only works forcomptime_int
, but I'd expect it to work for any comptime known value regardless of the type. Ideally such a workaround wouldn't be necessary and I'd use@mod
and@divFloor
directlyThe text was updated successfully, but these errors were encountered: