[llvm] r202163 - [XCore] Prefer to word align functions.

Richard Osborne richard at xmos.com
Tue Feb 25 08:37:15 PST 2014


Author: friedgold
Date: Tue Feb 25 10:37:15 2014
New Revision: 202163

URL: http://llvm.org/viewvc/llvm-project?rev=202163&view=rev
Log:
[XCore] Prefer to word align functions.

The behaviour of the XCore's instruction buffer means that the performance
of the same code sequence can differ depending on whether it starts at a 4
byte aligned address or not. Since we don't model the instruction buffer
in the backend we have no way of knowing for sure if it is beneficial to
word align a specific function. However, in the absence of precise
modelling, it is better on balance to word align functions because:

* It makes a fetch-nop while executing the prologue slightly less likely.
* If we don't word align functions then a small perturbation in one
  function can have a dramatic knock on effect. If the size of the function
  changes it might change the alignment and therefore the performance of
  all the functions that happen to follow it in the binary. This butterfly
  effect makes it harder to reason about and measure the performance of
  code.

Added:
    llvm/trunk/test/CodeGen/XCore/align.ll
Modified:
    llvm/trunk/lib/Target/XCore/XCoreISelLowering.cpp

Modified: llvm/trunk/lib/Target/XCore/XCoreISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/XCoreISelLowering.cpp?rev=202163&r1=202162&r2=202163&view=diff
==============================================================================
--- llvm/trunk/lib/Target/XCore/XCoreISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/XCore/XCoreISelLowering.cpp Tue Feb 25 10:37:15 2014
@@ -182,6 +182,7 @@ XCoreTargetLowering::XCoreTargetLowering
   setTargetDAGCombine(ISD::ADD);
 
   setMinFunctionAlignment(1);
+  setPrefFunctionAlignment(2);
 }
 
 bool XCoreTargetLowering::isZExtFree(SDValue Val, EVT VT2) const {

Added: llvm/trunk/test/CodeGen/XCore/align.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/XCore/align.ll?rev=202163&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/XCore/align.ll (added)
+++ llvm/trunk/test/CodeGen/XCore/align.ll Tue Feb 25 10:37:15 2014
@@ -0,0 +1,15 @@
+; RUN: llc < %s -march=xcore | FileCheck %s
+
+; CHECK: .align 4
+; CHECK-LABEL: f:
+define void @f() nounwind {
+entry:
+  ret void
+}
+
+; CHECK: .align 2
+; CHECK-LABEL: g:
+define void @g() nounwind optsize {
+entry:
+  ret void
+}





More information about the llvm-commits mailing list