https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123333
Bug ID: 123333
Summary: Failure to optimize away if-then-else with a
compile-time computable condition
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: law at gcc dot gnu.org
Target Milestone: ---
Bohan Lei submitted a patch to avoid triggering an ICE in a couple RISC-V
bitmanip patterns. The particular assertion triggered indicates an
if-then-else condition that is compile-time computable as false. Filing mostly
for tracking purposes.
/* { dg-do link { target { rv64 } } } */
/* { dg-options "-march=rv64gc_zbb_zbs -mabi=lp64d -flto" } */
/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-O1" } } */
struct S {
int a;
char b;
int c;
} s;
const signed char c = -37;
int d;
struct S v1[] = {{0, 8}, 0, 0, -108976}, v2[] = {{}, 0, 0, 2804};
int a;
struct S v3[3];
int *p = &a;
void foo() {
int a;
if (a)
;
else if (v1[0].b)
s.a = 0;
else
d = 0;
if (*p)
if (v3[1].c)
if (1 ^ (d & c & v2[1].c & ~v1[1].c | s.a))
v3[2].c = 0;
}
int main() { foo(); }
The problem is combine fails to optimize this in simplify_if_then_else:
(if_then_else (eq (and:DI (reg:DI 155 [ d ])
(const_int 2176 [0x880]))
(const_int 1 [0x1]))
(label_ref 45)
(pc))