mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 21:08:36 +00:00
stage2: vectorize shl_with_overflow in LLVM backend
This commit is contained in:
parent
c641fb8f05
commit
c2cb9b7cad
@ -5899,26 +5899,30 @@ pub const FuncGen = struct {
|
||||
|
||||
const lhs_ty = self.air.typeOf(extra.lhs);
|
||||
const rhs_ty = self.air.typeOf(extra.rhs);
|
||||
const lhs_scalar_ty = lhs_ty.scalarType();
|
||||
const rhs_scalar_ty = rhs_ty.scalarType();
|
||||
|
||||
const dest_ty = self.air.typeOfIndex(inst);
|
||||
const llvm_dest_ty = try self.dg.llvmType(dest_ty);
|
||||
|
||||
const tg = self.dg.module.getTarget();
|
||||
|
||||
const casted_rhs = if (rhs_ty.bitSize(tg) < lhs_ty.bitSize(tg))
|
||||
const casted_rhs = if (rhs_scalar_ty.bitSize(tg) < lhs_scalar_ty.bitSize(tg))
|
||||
self.builder.buildZExt(rhs, try self.dg.llvmType(lhs_ty), "")
|
||||
else
|
||||
rhs;
|
||||
|
||||
const result = self.builder.buildShl(lhs, casted_rhs, "");
|
||||
const reconstructed = if (lhs_ty.isSignedInt())
|
||||
const reconstructed = if (lhs_scalar_ty.isSignedInt())
|
||||
self.builder.buildAShr(result, casted_rhs, "")
|
||||
else
|
||||
self.builder.buildLShr(result, casted_rhs, "");
|
||||
|
||||
const overflow_bit = self.builder.buildICmp(.NE, lhs, reconstructed, "");
|
||||
|
||||
const partial = self.builder.buildInsertValue(llvm_dest_ty.getUndef(), result, 0, "");
|
||||
return self.builder.buildInsertValue(partial, overflow_bit, 1, "");
|
||||
var ty_buf: Type.Payload.Pointer = undefined;
|
||||
const partial = self.builder.buildInsertValue(llvm_dest_ty.getUndef(), result, llvmFieldIndex(dest_ty, 0, tg, &ty_buf).?, "");
|
||||
return self.builder.buildInsertValue(partial, overflow_bit, llvmFieldIndex(dest_ty, 1, tg, &ty_buf).?, "");
|
||||
}
|
||||
|
||||
fn airAnd(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user