Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RISC-V] Miscompile at -O2 #84350

Closed
patrick-rivos opened this issue Mar 7, 2024 · 5 comments
Closed

[RISC-V] Miscompile at -O2 #84350

patrick-rivos opened this issue Mar 7, 2024 · 5 comments

Comments

@patrick-rivos
Copy link
Contributor

patrick-rivos commented Mar 7, 2024

Testcase:

int printf(const char *, ...);
long a;
short b = 2;
char c(unsigned char d, unsigned char e) { return e == 0 ?: d % e; }
int main() {
  char f;
  a = 1;
  f = c(0 <= 7, b);
  a ^= f;
  printf("%lX\n", a);
}

Commands:

> clang -O2 red.c -o red.out
> qemu-riscv64 red.out
FFFFFFFFFFFFFFFE
> clang red.c -o red.out
> qemu-riscv64 red.out
0

-opt-bisect-limit points to Type Promotion on function (main)

This is a recent regression.
Known good hash: 083d8aa
Known bad hash: 8f79cdd

Found via fuzzer

@topperc
Copy link
Collaborator

topperc commented Mar 7, 2024

Can you check if #84232 fixes this?

@llvmbot
Copy link
Member

llvmbot commented Mar 7, 2024

@llvm/issue-subscribers-backend-risc-v

Author: Patrick O'Neill (patrick-rivos)

Testcase: ```c int printf(const char *, ...); long a; short b = 2; char c(unsigned char d, unsigned char e) { return e == 0 ?: d % e; } int main() { char f; a = 1; f = c(0 <= 7, b); a ^= f; printf("%lX\n", a); } ```

Commands:

&gt; /scratch/tc-testing/tc-mar-5-llvm-slp-ice-2/build/bin/clang -O2 red.c -o red.out
&gt; /scratch/tc-testing/tc-mar-4-llvm/build/bin/qemu-riscv64 red.out
FFFFFFFFFFFFFFFE
&gt; /scratch/tc-testing/tc-mar-5-llvm-slp-ice-2/build/bin/clang red.c -o red.out
&gt; /scratch/tc-testing/tc-mar-4-llvm/build/bin/qemu-riscv64 red.out
0

-opt-bisect-limit points to Type Promotion on function (main)

This is a recent regression.
Known good hash: 083d8aa
Known bad hash: 8f79cdd

Found via fuzzer

@patrick-rivos
Copy link
Contributor Author

I checked out the head of the PR branch at #84232 and this issue does not exist there.

> clang -O3 red.c -o red.out
> qemu-riscv64 red.out
0

Thanks!

@topperc
Copy link
Collaborator

topperc commented Mar 7, 2024

Thanks for confirming. I'm trying to mitigate some of the fallout from that fix before committing it.

topperc added a commit that referenced this issue Mar 7, 2024
Select blocks poison, but AND/OR do not. We need to insert a freeze
to block poison propagation.

This creates suboptimal codegen which I will try to fix with other
patches. I'm prioritizing the correctness fix since we have 2 bug reports.

Fixes #84200 and #84350
@dtcxzyw
Copy link
Member

dtcxzyw commented Mar 8, 2024

Should be fixed by #84232.

@dtcxzyw dtcxzyw closed this as completed Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants