r219604 - [AArch64] Add workaround for Cortex-A53 erratum (835769)

Bradley Smith bradley.smith at arm.com
Mon Oct 13 03:16:06 PDT 2014


Author: brasmi01
Date: Mon Oct 13 05:16:06 2014
New Revision: 219604

URL: http://llvm.org/viewvc/llvm-project?rev=219604&view=rev
Log:
[AArch64] Add workaround for Cortex-A53 erratum (835769)

Some early revisions of the Cortex-A53 have an erratum (835769) whereby it is
possible for a 64-bit multiply-accumulate instruction in AArch64 state to
generate an incorrect result.  The details are quite complex and hard to
determine statically, since branches in the code may exist in some
circumstances, but all cases end with a memory (load, store, or prefetch)
instruction followed immediately by the multiply-accumulate operation.

The safest work-around for this issue is to make the compiler avoid emitting
multiply-accumulate instructions immediately after memory instructions and the
simplest way to do this is to insert a NOP.

This patch implements clang options to enable this workaround in the backend.

The work-around code generation is not enabled by default.


Added:
    cfe/trunk/test/Driver/aarch64-fix-cortex-a53-835769-cg.c   (with props)
    cfe/trunk/test/Driver/aarch64-fix-cortex-a53-835769.c   (with props)
Modified:
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=219604&r1=219603&r2=219604&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Oct 13 05:16:06 2014
@@ -1169,6 +1169,13 @@ def mno_long_calls : Flag<["-"], "mno-lo
 def mgeneral_regs_only : Flag<["-"], "mgeneral-regs-only">, Group<m_aarch64_Features_Group>,
   HelpText<"Generate code which only uses the general purpose registers (AArch64 only)">;
 
+def mfix_cortex_a53_835769 : Flag<["-"], "mfix-cortex-a53-835769">,
+  Group<m_aarch64_Features_Group>,
+  HelpText<"Workaround Cortex-A53 erratum 835769 (AArch64 only)">;
+def mno_fix_cortex_a53_835769 : Flag<["-"], "mno-fix-cortex-a53-835769">,
+  Group<m_aarch64_Features_Group>,
+  HelpText<"Don't workaround Cortex-A53 erratum 835769 (AArch64 only)">;
+
 def mvsx : Flag<["-"], "mvsx">, Group<m_ppc_Features_Group>;
 def mno_vsx : Flag<["-"], "mno-vsx">, Group<m_ppc_Features_Group>;
 def mpower8_vector : Flag<["-"], "mpower8-vector">,

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=219604&r1=219603&r2=219604&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Mon Oct 13 05:16:06 2014
@@ -913,6 +913,15 @@ void Clang::AddAArch64TargetArgs(const A
       CmdArgs.push_back("-aarch64-no-strict-align");
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mfix_cortex_a53_835769,
+                               options::OPT_mno_fix_cortex_a53_835769)) {
+    CmdArgs.push_back("-backend-option");
+    if (A->getOption().matches(options::OPT_mfix_cortex_a53_835769))
+      CmdArgs.push_back("-aarch64-fix-cortex-a53-835769=1");
+    else
+      CmdArgs.push_back("-aarch64-fix-cortex-a53-835769=0");
+  }
+
   // Setting -mno-global-merge disables the codegen global merge pass. Setting
   // -mglobal-merge has no effect as the pass is enabled by default.
   if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge,

Added: cfe/trunk/test/Driver/aarch64-fix-cortex-a53-835769-cg.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/aarch64-fix-cortex-a53-835769-cg.c?rev=219604&view=auto
==============================================================================
--- cfe/trunk/test/Driver/aarch64-fix-cortex-a53-835769-cg.c (added)
+++ cfe/trunk/test/Driver/aarch64-fix-cortex-a53-835769-cg.c Mon Oct 13 05:16:06 2014
@@ -0,0 +1,19 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang -O3 -target aarch64-linux-eabi %s -S -o- \
+// RUN:   | FileCheck --check-prefix=CHECK-NO --check-prefix=CHECK %s
+// RUN: %clang -O3 -target aarch64-linux-eabi -mfix-cortex-a53-835769 %s -S -o- 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-YES --check-prefix=CHECK %s
+// RUN: %clang -O3 -target aarch64-linux-eabi -mno-fix-cortex-a53-835769 %s -S -o- 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO --check-prefix=CHECK %s
+
+#include <stdint.h>
+
+int64_t f_load_madd_64(int64_t a, int64_t b, int64_t *c) {
+    int64_t result = a+b*(*c);
+    return result;
+}
+
+// CHECK: ldr
+// CHECK-YES-NEXT: nop
+// CHECK-NO-NEXT-NOT: nop
+// CHECK-NEXT: madd

Propchange: cfe/trunk/test/Driver/aarch64-fix-cortex-a53-835769-cg.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/Driver/aarch64-fix-cortex-a53-835769-cg.c
------------------------------------------------------------------------------
    svn:keywords = Rev Date Author URL Id

Added: cfe/trunk/test/Driver/aarch64-fix-cortex-a53-835769.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/aarch64-fix-cortex-a53-835769.c?rev=219604&view=auto
==============================================================================
--- cfe/trunk/test/Driver/aarch64-fix-cortex-a53-835769.c (added)
+++ cfe/trunk/test/Driver/aarch64-fix-cortex-a53-835769.c Mon Oct 13 05:16:06 2014
@@ -0,0 +1,9 @@
+// RUN: %clang -target aarch64-linux-eabi %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-DEF %s
+// RUN: %clang -target aarch64-linux-eabi -mfix-cortex-a53-835769 %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-YES %s
+// RUN: %clang -target aarch64-linux-eabi -mno-fix-cortex-a53-835769 %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO %s
+// CHECK-DEF-NOT: "-backend-option" "-aarch64-fix-cortex-a53-835769"
+// CHECK-YES: "-backend-option" "-aarch64-fix-cortex-a53-835769=1"
+// CHECK-NO: "-backend-option" "-aarch64-fix-cortex-a53-835769=0"

Propchange: cfe/trunk/test/Driver/aarch64-fix-cortex-a53-835769.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/Driver/aarch64-fix-cortex-a53-835769.c
------------------------------------------------------------------------------
    svn:keywords = Rev Date Author URL Id





More information about the cfe-commits mailing list