authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-08-19 17:09:55-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-08-19 17:11:46-07:00
log47f7ed1c4cb8acf7fed99a057fb84202962e4b1b
tree914c255da590257af44db22099fdf9bc11ce8b9d
parent6926e6e705b7d1c0a69ec20b6b0e1ea280f036d1

Revert "Add mask before truncating dereferenced bit pointers (#9584)"

This was a workaround for an LLVM 12 bug which has been fixed in LLVM 13. This reverts commit 5cd1d42a351aa77d2a030e59cbd2b9abf7c44444 but keeps the test case.

1 files changed, 5 insertions(+), 8 deletions(-)

src/stage1/codegen.cpp+5-8
......@@ -3831,14 +3831,10 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, Stage1Air *executable,
38313831 LLVMValueRef shift_amt_val = LLVMConstInt(LLVMTypeOf(containing_int), shift_amt, false);
38323832 LLVMValueRef shifted_value = LLVMBuildLShr(g->builder, containing_int, shift_amt_val, "");
38333833
3834 LLVMTypeRef same_size_int = LLVMIntType(size_in_bits);
3835 LLVMValueRef mask = LLVMConstAllOnes(LLVMIntType(size_in_bits));
3836 mask = LLVMConstZExt(mask, LLVMTypeOf(containing_int));
3837 LLVMValueRef masked_value = LLVMBuildAnd(g->builder, shifted_value, mask, "");
3838
38393834 if (handle_is_ptr(g, child_type)) {
38403835 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
3841 LLVMValueRef truncated_int = LLVMBuildTrunc(g->builder, masked_value, same_size_int, "");
3836 LLVMTypeRef same_size_int = LLVMIntType(size_in_bits);
3837 LLVMValueRef truncated_int = LLVMBuildTrunc(g->builder, shifted_value, same_size_int, "");
38423838 LLVMValueRef bitcasted_ptr = LLVMBuildBitCast(g->builder, result_loc,
38433839 LLVMPointerType(same_size_int, 0), "");
38443840 LLVMBuildStore(g->builder, truncated_int, bitcasted_ptr);
......@@ -3846,11 +3842,12 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, Stage1Air *executable,
38463842 }
38473843
38483844 if (child_type->id == ZigTypeIdFloat) {
3849 LLVMValueRef truncated_int = LLVMBuildTrunc(g->builder, masked_value, same_size_int, "");
3845 LLVMTypeRef same_size_int = LLVMIntType(size_in_bits);
3846 LLVMValueRef truncated_int = LLVMBuildTrunc(g->builder, shifted_value, same_size_int, "");
38503847 return LLVMBuildBitCast(g->builder, truncated_int, get_llvm_type(g, child_type), "");
38513848 }
38523849
3853 return LLVMBuildTrunc(g->builder, masked_value, get_llvm_type(g, child_type), "");
3850 return LLVMBuildTrunc(g->builder, shifted_value, get_llvm_type(g, child_type), "");
38543851}
38553852
38563853static bool value_is_all_undef_array(CodeGen *g, ZigValue *const_val, size_t len) {