https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109269
Bug ID: 109269
Summary: [sve] should check the upper bound for predicate sve
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: zhongyunde at huawei dot com
Target Milestone: ---
* test case:https://gcc.godbolt.org/z/jde11xv53
```
void mset (int *a, long long num) {
for (long long i=0; i< num; i++)
a[i] = 2;
}
```
* Base on above case, gcc don't check the upper bound,
so when the input num is very large, such as 0xfffffffffffffffe, and the
vscale is 4 (512-bit scalable vector), so the "add x2, x2, x3" in the loop
body may be overflow, when the check "whilelo p0.s, x2, x1" will always be true
?
* see detail for gcc's assemble
```
mset:
cmp x1, 0
ble .L1
mov x2, 0
cntw x3
whilelo p0.s, xzr, x1
mov z0.s, #2
.L3:
st1w z0.s, p0, [x0, x2, lsl 2]
add x2, x2, x3 -- may be overflow ?
whilelo p0.s, x2, x1
b.any .L3
.L1:
ret
```