You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
D101191 in instcombine exposed a miscompile on an internal test, which goes away when disabling SLP vectorizer.
The following generates the incorrect result with "clang++ -msse4.2 -O2 repro.cc", but the correct result with "clang++ -msse4.2 -O2 repro.cc -fno-slp-vectorize":
#include <cstdint>
#include <cstdio>
// Needed to reproduce the issue with a small sample
template <class T>
void DoNotOptimize(const T& var) {
asm volatile("" : "+m"(const_cast<T&>(var)));
}
struct Stats {
int64_t x = 0;
int64_t total = 0;
};
Stats GetStats(float a, float b) {
float c = b ? a / b : 0.0;
bool is_outside_a = a <= 0 || a >= 2000;
bool is_outside_b = b <= 1 || b >= 2;
bool is_outside_c = c <= 50 || c >= 1000;
Stats stats;
stats.x = is_outside_b && is_outside_c ? 1 : 0;
stats.total = (is_outside_a || is_outside_b) ? 1 : 0;
DoNotOptimize(stats);
return stats;
}
int main() {
float a = 1000.0;
float b = 0.1;
DoNotOptimize(a);
DoNotOptimize(b);
const auto stats = GetStats(a, b);
printf("total = %ld\n", stats.total);
return stats.total == 1 ? 0 : 1;
}
In this example, a is 1000 (inside the first range), b is 0.1 (outside the range), and c is 10000 (outside the range). Therefore:
As with bug 49832, it's more general than partial undef - we don't account for vector transforms in our equivalence substituation logic: https://reviews.llvm.org/rG7bb8bfa0622b
I audited callers and don't see any other places we could hit this, so I put an assert in the simplify code.
If we want this kind of transform for vectors, we might try to handle splats only, but I don't see any evidence for it.
I think this bug was completely hidden before D101191, so it doesn't affect release branches, but feel free to reopen if that's not right.
Extended Description
D101191 in instcombine exposed a miscompile on an internal test, which goes away when disabling SLP vectorizer.
The following generates the incorrect result with "clang++ -msse4.2 -O2 repro.cc", but the correct result with "clang++ -msse4.2 -O2 repro.cc -fno-slp-vectorize":
In this example, a is 1000 (inside the first range), b is 0.1 (outside the range), and c is 10000 (outside the range). Therefore:
However, with SLP vectorizer enabled, stats.total is 0, when it should be 1.
The following IR was reduced from the C++ above, and can reproduce the difference with the same invocations:
The text was updated successfully, but these errors were encountered: