Commit cb661ed
Fix SkipStages narrowing
SkipStages::visit(Select) was combining each branch's `loaded` predicate
with the select condition (via make_select / make_and). That's wrong:
Halide's Select evaluates both branches and only picks one of the
results, so any load inside either branch fires unconditionally. The
`loaded` predicate must be the OR of both branches, ungated by the
condition.
The bug caused allocation bounds inference to size affected buffers down
to zero whenever the runtime condition was false, while the generated
code still emitted a vectorized load from them -- a heap OOB read that
showed up intermittently as a valgrind use-after-free on the
truncated_pyramid test.
Keep `used` gated by the condition as before (with the same select/and
collapse that fixed the exponential blow-up in #9147).
Add a regression test in skip_stages.cpp that records the minimum
producer allocation size through a custom malloc handler and verifies
it's non-zero when the producer's only consumer is inside a
runtime-false select branch.
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>loaded by Select condition (#9152)1 parent 642087f commit cb661ed
2 files changed
Lines changed: 62 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
488 | 488 | | |
489 | 489 | | |
490 | 490 | | |
491 | | - | |
492 | | - | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | 491 | | |
497 | 492 | | |
498 | 493 | | |
| |||
505 | 500 | | |
506 | 501 | | |
507 | 502 | | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
508 | 506 | | |
509 | 507 | | |
510 | | - | |
| 508 | + | |
511 | 509 | | |
512 | 510 | | |
513 | 511 | | |
514 | | - | |
| 512 | + | |
515 | 513 | | |
516 | 514 | | |
517 | 515 | | |
| |||
521 | 519 | | |
522 | 520 | | |
523 | 521 | | |
524 | | - | |
| 522 | + | |
525 | 523 | | |
526 | 524 | | |
527 | 525 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
13 | 29 | | |
14 | 30 | | |
15 | 31 | | |
| |||
245 | 261 | | |
246 | 262 | | |
247 | 263 | | |
248 | | - | |
| 264 | + | |
249 | 265 | | |
250 | 266 | | |
251 | 267 | | |
| |||
268 | 284 | | |
269 | 285 | | |
270 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
271 | 326 | | |
272 | 327 | | |
273 | 328 | | |
0 commit comments