Zig Version
0.16.0-dev.3041+3dc5f1398
Steps to Reproduce and Observed Behavior
const std = @import("std");
pub inline fn pdep(a: u32, mask: u32) u32 {
return asm ("pdep %[mask], %[src], %[dst]"
: [dst] "=r" (-> u32),
: [src] "r" (a),
[mask] "r" (mask),
: .{ .cc = true });
}
pub fn rank_real(bitmap: u32, rank: u32) u32 {
const ONE: u32 = 1;
const zeros: u32 = ~bitmap;
const rank_bit: u32 = ONE << @intCast(rank);
const real_rank = pdep(rank_bit, zeros);
return @ctz(real_rank);
}
pub fn main() !void {
const bitmap: u32 = 0b00010110;
const rank: u32 = 3;
const res = rank_real(bitmap, rank);
std.debug.print("{d}\n", .{res});
}
zig build run would result in error:
src/main.zig:11:5: error: emit MIR failed: InvalidInstruction (Zig compiler bug)
pub fn rank_real(bitmap: u32, rank: u32) u32 {
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: error(x86_64_encoder): no encoding found for: none pdep r32 r64 eax none
but zig build run --release=fast gives correct output "6".
tested on 0.15.2, same behavior.
issue goes away if both pdep and rank_real are inline or both are not inline. it only appears with the code above(inline pdep and not inline rank_real).
Expected Behavior
zig build run
6
### Zig Version
0.16.0-dev.3041+3dc5f1398
### Steps to Reproduce and Observed Behavior
```
const std = @import("std");
pub inline fn pdep(a: u32, mask: u32) u32 {
return asm ("pdep %[mask], %[src], %[dst]"
: [dst] "=r" (-> u32),
: [src] "r" (a),
[mask] "r" (mask),
: .{ .cc = true });
}
pub fn rank_real(bitmap: u32, rank: u32) u32 {
const ONE: u32 = 1;
const zeros: u32 = ~bitmap;
const rank_bit: u32 = ONE << @intCast(rank);
const real_rank = pdep(rank_bit, zeros);
return @ctz(real_rank);
}
pub fn main() !void {
const bitmap: u32 = 0b00010110;
const rank: u32 = 3;
const res = rank_real(bitmap, rank);
std.debug.print("{d}\n", .{res});
}
```
zig build run would result in error:
```
src/main.zig:11:5: error: emit MIR failed: InvalidInstruction (Zig compiler bug)
pub fn rank_real(bitmap: u32, rank: u32) u32 {
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: error(x86_64_encoder): no encoding found for: none pdep r32 r64 eax none
```
but zig build run --release=fast gives correct output "6".
tested on 0.15.2, same behavior.
issue goes away if both pdep and rank_real are inline or both are not inline. it only appears with the code above(inline pdep and not inline rank_real).
### Expected Behavior
zig build run
6