| author | |
| committer | |
| log | 952d865bd231834adad30905c469edc5a46d000a |
| tree | 49fe04fcec82ad893fc012bfc02624dd086864fb |
| parent | 9c1c1d478d3f5a541c142bb32b22a77c2f500953 |
The cache entry must take into account the fact some functions operate on scalar types and some other on vectors of scalar types.
Fixes #101474 files changed, 17 insertions(+), 0 deletions(-)
src/stage1/all_types.hpp+1| ... | ... | @@ -1957,6 +1957,7 @@ struct ZigLLVMFnKey { |
| 1957 | 1957 | } bswap; |
| 1958 | 1958 | struct { |
| 1959 | 1959 | uint32_t bit_count; |
| 1960 | uint32_t vector_len; // 0 means not a vector | |
| 1960 | 1961 | } bit_reverse; |
| 1961 | 1962 | } data; |
| 1962 | 1963 | }; |
src/stage1/codegen.cpp+3| ... | ... | @@ -5175,11 +5175,13 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn |
| 5175 | 5175 | n_args = 2; |
| 5176 | 5176 | key.id = ZigLLVMFnIdCtz; |
| 5177 | 5177 | key.data.ctz.bit_count = (uint32_t)int_type->data.integral.bit_count; |
| 5178 | key.data.ctz.vector_len = vector_len; | |
| 5178 | 5179 | } else if (fn_id == BuiltinFnIdClz) { |
| 5179 | 5180 | fn_name = "ctlz"; |
| 5180 | 5181 | n_args = 2; |
| 5181 | 5182 | key.id = ZigLLVMFnIdClz; |
| 5182 | 5183 | key.data.clz.bit_count = (uint32_t)int_type->data.integral.bit_count; |
| 5184 | key.data.clz.vector_len = vector_len; | |
| 5183 | 5185 | } else if (fn_id == BuiltinFnIdPopCount) { |
| 5184 | 5186 | fn_name = "ctpop"; |
| 5185 | 5187 | n_args = 1; |
| ... | ... | @@ -5197,6 +5199,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn |
| 5197 | 5199 | n_args = 1; |
| 5198 | 5200 | key.id = ZigLLVMFnIdBitReverse; |
| 5199 | 5201 | key.data.bit_reverse.bit_count = (uint32_t)int_type->data.integral.bit_count; |
| 5202 | key.data.bit_reverse.vector_len = vector_len; | |
| 5200 | 5203 | } else { |
| 5201 | 5204 | zig_unreachable(); |
| 5202 | 5205 | } |
test/behavior.zig+1| ... | ... | @@ -128,6 +128,7 @@ test { |
| 128 | 128 | _ = @import("behavior/bugs/7250.zig"); |
| 129 | 129 | _ = @import("behavior/bugs/9584.zig"); |
| 130 | 130 | _ = @import("behavior/bugs/9967.zig"); |
| 131 | _ = @import("behavior/bugs/10147.zig"); | |
| 131 | 132 | _ = @import("behavior/byteswap.zig"); |
| 132 | 133 | _ = @import("behavior/byval_arg_var.zig"); |
| 133 | 134 | _ = @import("behavior/call_stage1.zig"); |
test/behavior/bugs/10147.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | test "uses correct LLVM builtin" { | |
| 4 | var x: u32 = 0x1; | |
| 5 | var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 }; | |
| 6 | // The stage1 compiler used to call the same builtin function for both | |
| 7 | // scalar and vector inputs, causing the LLVM module verification to fail. | |
| 8 | var a = @clz(u32, x); | |
| 9 | var b = @clz(u32, y); | |
| 10 | try std.testing.expectEqual(@as(u6, 31), a); | |
| 11 | try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b); | |
| 12 | } |