authorgravatar for william@sengir.comWilliam Sengir <william@sengir.com> 2022-03-26 15:41:44-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-16 13:55:26-07:00
logc2cb9b7cade597bc967620174b31db3895681f96
tree133169b0604665eb374abea29774fc8b8d972b25
parentc641fb8f05cfbca7484a09496f33bc9c2d95941e

stage2: vectorize shl_with_overflow in LLVM backend


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

src/codegen/llvm.zig+8-4
......@@ -5899,26 +5899,30 @@ pub const FuncGen = struct {
58995899
59005900 const lhs_ty = self.air.typeOf(extra.lhs);
59015901 const rhs_ty = self.air.typeOf(extra.rhs);
5902 const lhs_scalar_ty = lhs_ty.scalarType();
5903 const rhs_scalar_ty = rhs_ty.scalarType();
5904
59025905 const dest_ty = self.air.typeOfIndex(inst);
59035906 const llvm_dest_ty = try self.dg.llvmType(dest_ty);
59045907
59055908 const tg = self.dg.module.getTarget();
59065909
5907 const casted_rhs = if (rhs_ty.bitSize(tg) < lhs_ty.bitSize(tg))
5910 const casted_rhs = if (rhs_scalar_ty.bitSize(tg) < lhs_scalar_ty.bitSize(tg))
59085911 self.builder.buildZExt(rhs, try self.dg.llvmType(lhs_ty), "")
59095912 else
59105913 rhs;
59115914
59125915 const result = self.builder.buildShl(lhs, casted_rhs, "");
5913 const reconstructed = if (lhs_ty.isSignedInt())
5916 const reconstructed = if (lhs_scalar_ty.isSignedInt())
59145917 self.builder.buildAShr(result, casted_rhs, "")
59155918 else
59165919 self.builder.buildLShr(result, casted_rhs, "");
59175920
59185921 const overflow_bit = self.builder.buildICmp(.NE, lhs, reconstructed, "");
59195922
5920 const partial = self.builder.buildInsertValue(llvm_dest_ty.getUndef(), result, 0, "");
5921 return self.builder.buildInsertValue(partial, overflow_bit, 1, "");
5923 var ty_buf: Type.Payload.Pointer = undefined;
5924 const partial = self.builder.buildInsertValue(llvm_dest_ty.getUndef(), result, llvmFieldIndex(dest_ty, 0, tg, &ty_buf).?, "");
5925 return self.builder.buildInsertValue(partial, overflow_bit, llvmFieldIndex(dest_ty, 1, tg, &ty_buf).?, "");
59225926 }
59235927
59245928 fn airAnd(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {