diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2023-12-28 14:03:50 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2023-12-28 15:02:02 +0100 |
commit | 365b95203727997534bd044a231737d057747186 (patch) | |
tree | fb57d8d90c1a01f422d5cc372bf50f144a867325 | |
parent | adceff0ab6e3d8bf43de52e2c2fbebf27db30deb (diff) | |
download | sparse-dev-fix-zephyr.tar.gz |
reassoc: fix infinite loop during reassociationfix-zephyr
The infinite loop is triggered by some fairly simple code on Zephyr and is
caused by some exchange of pseudos done without checking the canonical order.
Fix this by adding the check for the canonical order.
Also use can_move_to() instead of the simpler one_use() to check the dominance
of the moved pseudos.
Link: https://github.com/zephyrproject-rtos/zephyr/issues/63417
Link: https://lore.kernel.org/linux-sparse/AD16C022-C5F3-4DA2-A1A0-775E4C95A7A1@intel.com/
Reported-by: Marc Herbert <marc.herbert@intel.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 10 | ||||
-rw-r--r-- | validation/optim/bool-simplify2.c | 5 | ||||
-rw-r--r-- | validation/reassoc/bug-zephyr-63417.c | 13 |
3 files changed, 22 insertions, 6 deletions
@@ -1818,10 +1818,12 @@ static int simplify_associative_binop(struct instruction *insn) insn->src2 = eval_op(insn->opcode, insn->size, insn->src2, def->src2); return replace_pseudo(insn, &insn->src1, def->src1); } - if (!one_use(def->target)) - return 0; - switch_pseudo(def, &def->src1, insn, &insn->src2); - return REPEAT_CSE; + + if (!canonical_order(def->src1, insn->src2) && can_move_to(insn->src2, def)) { + // (x # y) # z -> (z # y) # x when x ≻ z + return switch_pseudo(def, &def->src1, insn, &insn->src2); + } + return 0; } static int simplify_add_one_side(struct instruction *insn, pseudo_t *p1, pseudo_t *p2) diff --git a/validation/optim/bool-simplify2.c b/validation/optim/bool-simplify2.c index a089fe62..cf322725 100644 --- a/validation/optim/bool-simplify2.c +++ b/validation/optim/bool-simplify2.c @@ -28,10 +28,11 @@ static bool babbb(bool a, bool b, bool c) { return a && b && c; } * check-command: test-linearize $file * * check-output-pattern(20): setne\\. - * check-output-pattern(4): seteq\\. + * check-output-pattern(3): seteq\\. * check-output-pattern(8): zext\\. * check-output-pattern(12): and * check-output-pattern(12): or + * check-output-pattern(1): not * check-output-end * * check-output-start @@ -143,7 +144,7 @@ inb: bnb: .L22: <entry-point> - seteq.1 %r93 <- %arg1, $0 + not.1 %r93 <- %arg1 ret.1 %r93 diff --git a/validation/reassoc/bug-zephyr-63417.c b/validation/reassoc/bug-zephyr-63417.c new file mode 100644 index 00000000..5db821d3 --- /dev/null +++ b/validation/reassoc/bug-zephyr-63417.c @@ -0,0 +1,13 @@ +extern char __tdata_size[]; +extern char __tdata_align[]; + +unsigned long z_tls_data_size(void); +unsigned long z_tls_data_size(void) +{ + return ((unsigned long)__tdata_size) + ((unsigned long)__tdata_align - 1); +} + +/* + * check-name: bug-zephyr-63417 + * check-timeout: + */ |