Skip to content

Commit 766cab6

Browse files
authored
[LoadStoreConversion] Handle negative indices in boundary checks (#3429)
Fixes #3240 --------- Signed-off-by: dchigarev <[email protected]>
1 parent c89d657 commit 766cab6

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

third_party/intel/lib/TritonIntelGPUToLLVM/LoadStoreOpToLLVM.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,11 @@ struct LoadStoreConversionBase {
263263
{blockPtr.begin() + blockShape, blockPtr.begin() + blockStride},
264264
b.int_val(1, 1),
265265
[&](const Value &index, const Value &shape, const Value &mask) {
266-
// mask = mask && (index < shape)
267-
return b.and_(b.icmp_slt(index, b.trunc(i32_ty, shape)), mask);
266+
// mask = mask && (index < shape) && idx >= 0
267+
auto is_pos_idx = b.icmp_sge(index, b.int_val(32, 0));
268+
return b.and_(
269+
b.and_(b.icmp_slt(index, b.trunc(i32_ty, shape)), mask),
270+
is_pos_idx);
268271
}));
269272
}
270273
}

0 commit comments

Comments
 (0)