AccelerateHS / AccelerateHS/accelerate-llvm

[BUG] Conditional does not gate memory access unless in top-level expression

未关闭
#116 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Haskell
星标
171
派生
65
PR 合并指标
30 天内没有已合并 PR

描述

To prevent out-of-bounds accesses, conditionals (i.e. `?` operator or `cond`) can be used to check bounds ahead of accessing those arrays. For example the following correctly guards against OOB access:
```
foo = generate (I1 10) $ \(I1 i) ->
i < length bar ? (bar !! i, 0)
```
however, the following does not generate code which correctly guards against OOB access but should:
```
foo = generate (I1 10) $ \(I1 i) ->
T2 (i < length bar ? (bar !! i, 0))
(i < length bar ? ((bar !! i) + 1, 1))
```
This is not an exact reproduction of my scenario but it is similar. Principally what I observer in the generated LLVM output is the `bar` access taking place without first checking if `i < length bar`. This has lead to OOB accesses. When I instead do the following:
```
foo = generate (I1 10) $ \(I1 i) ->
i < length bar ? (T2 (bar !! i) ((bar !! i) + 1), T2 0 1)
```
the OOB access disappears.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。