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
{{ message }}
Repository navigation
assert in Reassociate::OptimizeAdd fires when it shouldn't due to miscounted multiplicative factors #6829
Description
Assert fires on valid code, when asserts are enabled.
Steps to Reproduce
The compiler asserts, when asserts are on, in the following case.
Compile with dxc -HV 2018 a.hlsl -T cs_6_0 -E m
int2 tint_mod(int2 lhs, int rhs) {
int2 r = int2((rhs).xx);
int2 rhs_or_one = (((r == (0).xx) | ((lhs == (-2147483648).xx) & (r == (-1).xx))) ? (1).xx : r);
if (any(((uint2((lhs | rhs_or_one)) & (2147483648u).xx) != (0u).xx))) {
return (lhs - ((lhs / rhs_or_one) * rhs_or_one));
} else {
return (lhs % rhs_or_one);
}
}
int2 tint_mod_1(int2 lhs, int2 rhs) {
int2 rhs_or_one = (((rhs == (0).xx) | ((lhs == (-2147483648).xx) & (rhs == (-1).xx))) ? (1).xx : rhs);
if (any(((uint2((lhs | rhs_or_one)) & (2147483648u).xx) != (0u).xx))) {
return (lhs - ((lhs / rhs_or_one) * rhs_or_one));
} else {
return (lhs % rhs_or_one);
}
}
[numthreads(1,1,1)]
void m() {
float x = ddy(0.0f);
bool2 y = bool2((x>0).xx); // simplified from origial case
int2 w = ~(~(~(~(~(~(~(-(~(~(~(~(~(int2(y))))))))))))));
int2 w6 = (w + (((((((~(-(~(~(~(~(~(~(w)))))))) - -(w)) - (-(w) * 2)) - w) - w) - ~(-(w))) - tint_mod(w, 4)) - 1));
int2 w5 = tint_mod(-(w6), 2); // power of 2 is required here
int2 w4 = tint_mod(w5, w6.x);
int2 w3 = tint_mod(w4, 2); // power of 2 is reuquired here
int2 w2 = tint_mod(w3, 5); // anything more than 1
int2 w1 = tint_mod(w2, w6.x);
w = tint_mod(w, w1.x);
return;
}
Sorry, this is as reduced as I can make it.
The code is in the middle of rewriting expressions like (AB + AC + D) to pull common factor A out, and it finds that there's actually only one A. This can occur when A is a constant, and -A also appears in the terms.
It's a long story, but this has been fixed upstream already, with llvm/llvm-project@95abfa3
That fix ensures that when a negative constant factor is found, don't double count its positive counterpart in case it has already been seen as a factor.
Actual Behavior
The assert is:
opt: /dxc/lib/Transforms/Scalar/Reassociate.cpp:1740: Value *(anonymous namespace)::Reassociate::OptimizeAdd(Instruction *, SmallVectorImpl &): Assertion `NumAddedValues > 1 && "Each occurrence should contribute a value"' failed.
FileCheck error: '-' is empty.
Activity
Reassociation: fix counting of constant multiplicative factors
Reassociation: fix counting of constant multiplicative factors
Reassociation: fix counting of constant multiplicative factors (micro…
Reassociation: fix counting of constant multiplicative factors (micro…
Update submodules: DirectX-Headers to 61c77189, SPIRV-Headers to 5c60…
Update submodules: DirectX-Headers to 61c77189, SPIRV-Headers to 5c60…