llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.21k stars 11.64k forks source link

[clang] Assertion failed in Vectorize #109528

Open cardigan1008 opened 1 week ago

cardigan1008 commented 1 week ago

When I compiled this code with O2 flag, it crashed:

#include <stdint.h>
static uint64_t
safe_sub_func_uint64_t_u_u(uint64_t ui1, uint64_t ui2)
{
  return ui1 - ui2;
}
long a;
static int8_t c;
void b(long d, int f) {
  int e = 0;
  for (; e < 64; e++)
    if (e - f)
      a |= e >> f;
    else
      a |= d & e;
}
uint32_t g() {
  b(6, c);
  for (;; c = safe_sub_func_uint64_t_u_u(c, 4))
    ;
}

The crash is:

clang: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7383: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && " VPlan cost model and legacy cost model disagreed"' failed.

Details can be found here: https://godbolt.org/z/7733x1hvP

shafik commented 1 week ago

This looks like a regression in trunk: https://godbolt.org/z/eo7WG1e66

hiraditya commented 2 days ago

Probably a recent change caused this? cc: @ayalz @fhahn