Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 39 additions & 19 deletions src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,25 +1183,45 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, Value **arg
case or_int: return ctx.builder.CreateOr(x, y);
case xor_int: return ctx.builder.CreateXor(x, y);

case shl_int:
return ctx.builder.CreateSelect(
ctx.builder.CreateICmpUGE(y, ConstantInt::get(y->getType(),
t->getPrimitiveSizeInBits())),
ConstantInt::get(t, 0),
ctx.builder.CreateShl(x, uint_cnvt(ctx, t, y)));
case lshr_int:
return ctx.builder.CreateSelect(
ctx.builder.CreateICmpUGE(y, ConstantInt::get(y->getType(),
t->getPrimitiveSizeInBits())),
ConstantInt::get(t, 0),
ctx.builder.CreateLShr(x, uint_cnvt(ctx, t, y)));
case ashr_int:
return ctx.builder.CreateSelect(
ctx.builder.CreateICmpUGE(y, ConstantInt::get(y->getType(),
t->getPrimitiveSizeInBits())),
ctx.builder.CreateAShr(x, ConstantInt::get(t, t->getPrimitiveSizeInBits() - 1)),
ctx.builder.CreateAShr(x, uint_cnvt(ctx, t, y)));

case shl_int: {
Value *the_shl = ctx.builder.CreateShl(x, uint_cnvt(ctx, t, y));
if (ConstantInt::isValueValidForType(y->getType(), t->getPrimitiveSizeInBits())) {
return ctx.builder.CreateSelect(
ctx.builder.CreateICmpUGE(y, ConstantInt::get(y->getType(),
t->getPrimitiveSizeInBits())),
ConstantInt::get(t, 0),
the_shl);
}
else {
return the_shl;
}
}
case lshr_int: {
Value *the_shr = ctx.builder.CreateLShr(x, uint_cnvt(ctx, t, y));
if (ConstantInt::isValueValidForType(y->getType(), t->getPrimitiveSizeInBits())) {
return ctx.builder.CreateSelect(
ctx.builder.CreateICmpUGE(y, ConstantInt::get(y->getType(),
t->getPrimitiveSizeInBits())),
ConstantInt::get(t, 0),
the_shr);
}
else {
return the_shr;
}
}
case ashr_int: {
Value *the_shr = ctx.builder.CreateAShr(x, uint_cnvt(ctx, t, y));
if (ConstantInt::isValueValidForType(y->getType(), t->getPrimitiveSizeInBits())) {
return ctx.builder.CreateSelect(
ctx.builder.CreateICmpUGE(y, ConstantInt::get(y->getType(),
t->getPrimitiveSizeInBits())),
ctx.builder.CreateAShr(x, ConstantInt::get(t, t->getPrimitiveSizeInBits() - 1)),
the_shr);
}
else {
return the_shr;
}
}
case bswap_int: {
FunctionCallee bswapintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::bswap, makeArrayRef(t));
return ctx.builder.CreateCall(bswapintr, x);
Expand Down
16 changes: 16 additions & 0 deletions test/compiler/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,19 @@ let d = Dict((:a,) => 1, (:a, :b) => 2)
@test d[(:a,)] == 1
@test d[(:a, :b)] == 2
end

# issue #37880
primitive type Has256Bits 256 end
let x = reinterpret(Has256Bits, [0xfcdac822cac89d82de4f9b3326da8294, 0x6ebac4d5982880ca703c57e37657f1ee])[]
shifted = [0xeefcdac822cac89d82de4f9b3326da82, 0x006ebac4d5982880ca703c57e37657f1]
f(x) = Base.lshr_int(x, 0x8)
@test reinterpret(UInt128, [f(x)]) == shifted
@test reinterpret(UInt128, [Base.lshr_int(x, 0x8)]) == shifted
g(x) = Base.ashr_int(x, 0x8)
@test reinterpret(UInt128, [g(x)]) == shifted
@test reinterpret(UInt128, [Base.ashr_int(x, 0x8)]) == shifted
lshifted = [0xdac822cac89d82de4f9b3326da829400, 0xbac4d5982880ca703c57e37657f1eefc]
h(x) = Base.shl_int(x, 0x8)
@test reinterpret(UInt128, [h(x)]) == lshifted
@test reinterpret(UInt128, [Base.shl_int(x, 0x8)]) == lshifted
end