tree-optimization/102008 - restore if-conversion of adjacent loads
authorRichard Biener <rguenther@suse.de>
Wed, 16 Mar 2022 12:39:31 +0000 (13:39 +0100)
committerRichard Biener <rguenther@suse.de>
Wed, 16 Mar 2022 13:00:35 +0000 (14:00 +0100)
The following re-orders the newly added code sinking pass before
the last phiopt pass which performs hoisting of adjacent loads
with the intent to enable if-conversion on those.

I've added the aarch64 specific testcase from the PR.

2022-03-16  Richard Biener  <rguenther@suse.de>

PR tree-optimization/102008
* passes.def: Move the added code sinking pass before the
preceeding phiopt pass.

* gcc.target/aarch64/pr102008.c: New testcase.

gcc/passes.def
gcc/testsuite/gcc.target/aarch64/pr102008.c [new file with mode: 0644]

index f771818..c8903b4 100644 (file)
@@ -349,10 +349,10 @@ along with GCC; see the file COPYING3.  If not see
       /* After late CD DCE we rewrite no longer addressed locals into SSA
         form if possible.  */
       NEXT_PASS (pass_forwprop);
+      NEXT_PASS (pass_sink_code);
       NEXT_PASS (pass_phiopt, false /* early_p */);
       NEXT_PASS (pass_fold_builtins);
       NEXT_PASS (pass_optimize_widening_mul);
-      NEXT_PASS (pass_sink_code);
       NEXT_PASS (pass_store_merging);
       NEXT_PASS (pass_tail_calls);
       /* If DCE is not run before checking for uninitialized uses,
diff --git a/gcc/testsuite/gcc.target/aarch64/pr102008.c b/gcc/testsuite/gcc.target/aarch64/pr102008.c
new file mode 100644 (file)
index 0000000..d54436c
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+struct Foo {  int a;  int b; };
+
+int test(int side, const struct Foo *foo) {
+  if (side == 1) return foo->a;
+  return foo->b;
+}
+
+/* We want to if-convert the load, not the address.  */
+/* { dg-final { scan-assembler-not "add" } } */
+/* { dg-final { scan-assembler-times "csel" 1 } } */