Skip to content

Commit

Permalink
Bit-shift expressions: Cast scalar right-hand-sides to vectors if needed
Browse files Browse the repository at this point in the history
This promotion from scalar right-hand-sides to vectors already happens
for the arithmetic binops, via `typeCombine()` side effects. Handle
bit-shift expressions too now, by casting a scalar to the left-hand-side
vector type.

This can't be tested with DMD, as DMD's `Target.isVectorOpSupported()`
doesn't support bit-shifts yet. It is ~required/useful for LDC though.
  • Loading branch information
kinke committed Nov 13, 2024
1 parent dcecb46 commit e8cd20e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -13114,9 +13114,13 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
result = exp.incompatibleTypes();
return;
}

exp.e1 = integralPromotions(exp.e1, sc);
if (exp.e2.type.toBasetype().ty != Tvector)
exp.e2 = exp.e2.castTo(sc, Type.tshiftcnt);
{
Type tb1 = exp.e1.type.toBasetype();
exp.e2 = exp.e2.castTo(sc, tb1.ty == Tvector ? tb1 : Type.tshiftcnt);
}

exp.type = exp.e1.type;
result = exp;
Expand Down

0 comments on commit e8cd20e

Please sign in to comment.