The sign bit of a sign-extending load cannot be known until runtime, so don't attempt to simplify it in the combiner.
2024-01-11 Greg McGary <g...@rivosinc.com> PR rtl-optimization/113010 * combine.cc (expand_compound_operation): Don't simplify SIGN_EXTEND of a MEM on WORD_REGISTER_OPERATIONS targets * gcc.c-torture/execute/pr113010.c: New test. --- gcc/combine.cc | 5 +++++ gcc/testsuite/gcc.c-torture/execute/pr113010.c | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr113010.c diff --git a/gcc/combine.cc b/gcc/combine.cc index 812553c091e..ba587184dfc 100644 --- a/gcc/combine.cc +++ b/gcc/combine.cc @@ -7208,6 +7208,11 @@ expand_compound_operation (rtx x) if (len == 0) return x; + /* Sign-extending loads can never be simplified at compile time. */ + if (WORD_REGISTER_OPERATIONS && MEM_P (XEXP (x, 0)) + && load_extend_op (inner_mode) == SIGN_EXTEND) + return x; + break; case ZERO_EXTRACT: diff --git a/gcc/testsuite/gcc.c-torture/execute/pr113010.c b/gcc/testsuite/gcc.c-torture/execute/pr113010.c new file mode 100644 index 00000000000..a95c613c1df --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr113010.c @@ -0,0 +1,9 @@ +int minus_1 = -1; + +int +main () +{ + if ((0, 0xfffffffful) >= minus_1) + __builtin_abort (); + return 0; +} -- 2.34.1