Skip to content

Commit bed0ae8

Browse files
committed
Generalize vectorized addition to notice that uniform + contiguous is contiguous, not varying.
This is relevant for preserving vector loads when an index is offset.
1 parent 1728824 commit bed0ae8

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/lib/Vectorize.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,13 @@ vectorizePrimOp op = case op of
487487
BinOp opk arg1 arg2 -> do
488488
sx@(VVal vx x) <- vectorizeAtom arg1
489489
sy@(VVal vy y) <- vectorizeAtom arg2
490-
let v = case (vx, vy) of (Uniform, Uniform) -> Uniform; _ -> Varying
491-
x' <- if vx /= v then ensureVarying sx else return x
492-
y' <- if vy /= v then ensureVarying sy else return y
490+
let v = case (opk, vx, vy) of
491+
(_, Uniform, Uniform) -> Uniform
492+
(IAdd, Uniform, Contiguous) -> Contiguous
493+
(IAdd, Contiguous, Uniform) -> Contiguous
494+
_ -> Varying
495+
x' <- if v == Varying then ensureVarying sx else return x
496+
y' <- if v == Varying then ensureVarying sy else return y
493497
VVal v <$> emitOp (BinOp opk x' y')
494498
MiscOp (CastOp tyArg arg) -> do
495499
ty <- vectorizeType tyArg

tests/opt-tests.dx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ _ = for i:(Fin 20) j:(Fin 4). ordinal j
126126
"vectorizing int binary op"
127127
-- CHECK-LABEL: vectorizing int binary op
128128
%passes vect
129-
_ = for i:(Fin 256). (n_to_i32 (ordinal i)) + 1
129+
_ = for i:(Fin 256). (n_to_i32 (ordinal i)) * 2
130130
-- CHECK: seq (RawFin 0x10)
131131
-- CHECK: [[i0:v#[0-9]+]]:<16xInt32> = vbroadcast
132132
-- CHECK: [[i1:v#[0-9]+]]:<16xInt32> = viota
133133
-- CHECK: [[i2:v#[0-9]+]]:<16xInt32> = %iadd [[i0]] [[i1]]
134-
-- CHECK: [[ones:v#[0-9]+]]:<16xInt32> = vbroadcast 1
135-
-- CHECK: %iadd [[i2]] [[ones]]
134+
-- CHECK: [[twos:v#[0-9]+]]:<16xInt32> = vbroadcast 2
135+
-- CHECK: %imul [[i2]] [[twos]]
136136

137137
"vectorizing float binary op"
138138
-- CHECK-LABEL: vectorizing float binary op

0 commit comments

Comments
 (0)