diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cf8e21201cb..ac8b18f1a84 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2020-01-23 Richard Sandiford + + PR target/93341 + * config/aarch64/aarch64.md (UNSPEC_SPECULATION_TRACKER_REV): New + unspec. + (speculation_tracker_rev): New pattern. + * config/aarch64/aarch64-speculation.cc (aarch64_do_track_speculation): + Use speculation_tracker_rev to track the inverse condition. + 2020-01-23 Richard Biener PR tree-optimization/93381 diff --git a/gcc/config/aarch64/aarch64-speculation.cc b/gcc/config/aarch64/aarch64-speculation.cc index 98dcc11fb75..f490b64ae61 100644 --- a/gcc/config/aarch64/aarch64-speculation.cc +++ b/gcc/config/aarch64/aarch64-speculation.cc @@ -215,20 +215,13 @@ aarch64_do_track_speculation () && REG_P (XEXP (cond, 0)) && REGNO (XEXP (cond, 0)) == CC_REGNUM && XEXP (cond, 1) == const0_rtx); - enum rtx_code inv_cond_code - = reversed_comparison_code (cond, insn); - /* We should be able to reverse all conditions. */ - gcc_assert (inv_cond_code != UNKNOWN); - rtx inv_cond = gen_rtx_fmt_ee (inv_cond_code, GET_MODE (cond), - copy_rtx (XEXP (cond, 0)), - copy_rtx (XEXP (cond, 1))); + rtx branch_tracker = gen_speculation_tracker (copy_rtx (cond)); + rtx fallthru_tracker = gen_speculation_tracker_rev (cond); if (inverted) - std::swap (cond, inv_cond); + std::swap (branch_tracker, fallthru_tracker); - insert_insn_on_edge (gen_speculation_tracker (cond), - BRANCH_EDGE (bb)); - insert_insn_on_edge (gen_speculation_tracker (inv_cond), - FALLTHRU_EDGE (bb)); + insert_insn_on_edge (branch_tracker, BRANCH_EDGE (bb)); + insert_insn_on_edge (fallthru_tracker, FALLTHRU_EDGE (bb)); needs_tracking = true; } else if (GET_CODE (PATTERN (insn)) == RETURN) diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index 55dde54b16a..4f5898185f5 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -262,6 +262,7 @@ UNSPEC_REV_SUBREG UNSPEC_REINTERPRET UNSPEC_SPECULATION_TRACKER + UNSPEC_SPECULATION_TRACKER_REV UNSPEC_COPYSIGN UNSPEC_TTEST ; Represent transaction test. UNSPEC_UPDATE_FFR @@ -7219,6 +7220,20 @@ [(set_attr "type" "csel")] ) +;; Like speculation_tracker, but track the inverse condition. +(define_insn "speculation_tracker_rev" + [(set (reg:DI SPECULATION_TRACKER_REGNUM) + (unspec:DI [(reg:DI SPECULATION_TRACKER_REGNUM) (match_operand 0)] + UNSPEC_SPECULATION_TRACKER_REV))] + "" + { + operands[1] = gen_rtx_REG (DImode, SPECULATION_TRACKER_REGNUM); + output_asm_insn ("csel\\t%1, %1, xzr, %M0", operands); + return ""; + } + [(set_attr "type" "csel")] +) + ;; BTI instructions (define_insn "bti_noarg" [(unspec_volatile [(const_int 0)] UNSPECV_BTI_NOARG)] diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8ad220e6941..7a03ebbaef8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-01-23 Richard Sandiford + + PR target/93341 + * gcc.target/aarch64/pr93341.c: New test. + 2020-01-23 David Malcolm * gcc.dg/analyzer/data-model-3.c: Remove hardcoded "-O2" and move diff --git a/gcc/testsuite/gcc.target/aarch64/pr93341.c b/gcc/testsuite/gcc.target/aarch64/pr93341.c new file mode 100644 index 00000000000..1efebeee21a --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr93341.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-mtrack-speculation" } */ + +int synths_ ( float * rc) +{ + float r1, r2; + int i; + for (i = 0; i < 128; ++i) + { + r2 = rc[i]; + r1 = ((r2) <= (.99f) ? (r2) : (.99f)); + rc[i] = ((r1) >= (-.99f) ? (r1) : (-.99f)); + } +}