forked from halide/Halide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[miscompile] Don't de-negate and change direction of shifts-by-unsigned
I'm afraid the problem is really obvious: https://github.com/halide/Halide/blob/b5f024fa83b6f1cfe5e83a459c9378b7c5bf096d/src/CodeGen_LLVM.cpp#L2628-L2649 ^ the shift direction is treated as flippable by the codegen iff the shift amount is signed :) The newly-added test fails without the fix. I've hit this when writing tests for halide#6775
- Loading branch information
Showing
3 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "Halide.h" | ||
|
||
using namespace Halide; | ||
|
||
template<typename T> | ||
bool test(Func f, T f_expected, int width) { | ||
Buffer<uint32_t> actual = f.realize({width}); | ||
for (int i = 0; i < actual.width(); i++) { | ||
if (actual(i) != f_expected(i)) { | ||
printf("r(%d) = %d, f_expected(%d) = %d\n", | ||
i, actual(i), i, f_expected(i)); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
Buffer<uint32_t> step(31); | ||
for (int i = 0; i < step.width(); i++) { | ||
step(i) = -i; | ||
} | ||
|
||
bool success = true; | ||
Var x; | ||
|
||
{ | ||
Func f; | ||
f(x) = Expr(-1U) << -step(x); | ||
auto f_expected = [&](int x) { | ||
return -1U << x; | ||
}; | ||
success &= test(f, f_expected, step.width()); | ||
} | ||
{ | ||
Func f; | ||
f(x) = Expr(-1U) >> -step(x); | ||
auto f_expected = [&](int x) { | ||
return -1U >> x; | ||
}; | ||
success &= test(f, f_expected, step.width()); | ||
} | ||
|
||
if (success) printf("Success!\n"); | ||
return success ? 0 : -1; | ||
} |