Halide
Halide copied to clipboard
Staging strided access to input buffer in a guardwithif generates a pointless if statement
This code:
#include "Halide.h"
using namespace Halide;
int main(int argc, char **argv) {
Func f, g;
Var x, y;
ImageParam im(UInt(8), 1);
g(x) = im(2 * x) + im(2 * x + 1);
g.vectorize(x, 32, TailStrategy::GuardWithIf);
im.in().compute_at(g, x).vectorize(_0, 64, TailStrategy::GuardWithIf);
g.compile_jit();
return 0;
}
Generates this IR, which includes an always-true if statement:
let t114 = g.extent.0/32
for (g.s0.x.x, 0, t114) {
allocate im_im_global_wrapper$0[uint8 * 64]
if ((g.s0.x.x*32) < g.extent.0) {
produce im_im_global_wrapper$0 {
im_im_global_wrapper$0[ramp(0, 1, 64)] = im[ramp((((g.s0.x.x*32) + g.min.0)*2) - im.min.0, 1, 64)]
}
}
consume im_im_global_wrapper$0 {
g[ramp(g.s0.x.x*32, 1, 32) aligned(32, 0)] = im_im_global_wrapper$0[ramp(0, 2, 32)] + im_im_global_wrapper$0[ramp(1, 2, 32)]
}
free im_im_global_wrapper$0
}
Is this if statement likely to be optimized away by LLVM (ie can it be proven always true or false)?
Sadly it is not optimized away