mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 12:59:04 +00:00
Liveness: fix branch operands becoming aliased
This commit is contained in:
parent
25a556107c
commit
024540de15
@ -599,7 +599,7 @@ pub fn categorizeOperand(
|
||||
|
||||
.br => {
|
||||
const br = air_datas[@intFromEnum(inst)].br;
|
||||
if (br.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .noret);
|
||||
if (br.operand == operand_ref) return matchOperandSmallIndex(l, operand, 0, .noret);
|
||||
return .noret;
|
||||
},
|
||||
.assembly => {
|
||||
|
||||
@ -167,3 +167,36 @@ test "if-@as-if chain" {
|
||||
|
||||
try expect(num_frames == 4);
|
||||
}
|
||||
|
||||
fn returnTrue() bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
test "if value shouldn't be load-elided if used later (structs)" {
|
||||
const Foo = struct { x: i32 };
|
||||
|
||||
var a = Foo{ .x = 1 };
|
||||
var b = Foo{ .x = 1 };
|
||||
|
||||
const c = if (@call(.never_inline, returnTrue, .{})) a else b;
|
||||
// The second variable is superfluous with the current
|
||||
// state of codegen optimizations, but in future
|
||||
// "if (smthg) a else a" may be optimized simply into "a".
|
||||
|
||||
a.x = 2;
|
||||
b.x = 3;
|
||||
|
||||
try std.testing.expectEqual(c.x, 1);
|
||||
}
|
||||
|
||||
test "if value shouldn't be load-elided if used later (optionals)" {
|
||||
var a: ?i32 = 1;
|
||||
var b: ?i32 = 1;
|
||||
|
||||
const c = if (@call(.never_inline, returnTrue, .{})) a else b;
|
||||
|
||||
a = 2;
|
||||
b = 3;
|
||||
|
||||
try std.testing.expectEqual(c, 1);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user