Index: include/llvm/Target/TargetLowering.h =================================================================== --- include/llvm/Target/TargetLowering.h +++ include/llvm/Target/TargetLowering.h @@ -979,6 +979,8 @@ /// Return the minimum function alignment. unsigned getMinFunctionAlignment() const { + if (CLFunctionAlignment > MinFunctionAlignment) + return CLFunctionAlignment; return MinFunctionAlignment; } @@ -987,6 +989,13 @@ return PrefFunctionAlignment; } + /// Return the minimum loop alignment. + unsigned getMinLoopAlignment() const { + if (CLLoopAlignment > MinLoopAlignment) + return CLLoopAlignment; + return MinLoopAlignment; + } + /// Return the preferred loop alignment. virtual unsigned getPrefLoopAlignment(MachineLoop *ML = nullptr) const { return PrefLoopAlignment; @@ -1842,9 +1851,20 @@ /// optimizing for speed). unsigned PrefFunctionAlignment; + /// The function alignment as specified on the command line. This is used + /// for debugging and test. + unsigned CLFunctionAlignment; + + /// The minimum loop alignment. + unsigned MinLoopAlignment; + /// The preferred loop alignment. unsigned PrefLoopAlignment; + /// The loop alignment as specified on the command line. This is used + /// for debugging and test. + unsigned CLLoopAlignment; + /// Whether the DAG builder should automatically insert fences and reduce /// ordering for atomics. (This will be set for for most architectures with /// weak memory ordering.) Index: lib/CodeGen/MachineBlockPlacement.cpp =================================================================== --- lib/CodeGen/MachineBlockPlacement.cpp +++ lib/CodeGen/MachineBlockPlacement.cpp @@ -1330,6 +1330,8 @@ continue; unsigned Align = TLI->getPrefLoopAlignment(L); + unsigned MinAlign = TLI->getMinLoopAlignment(); + Align = std::max(Align, MinAlign); if (!Align) continue; // Don't care about loop alignment. Index: lib/CodeGen/TargetLoweringBase.cpp =================================================================== --- lib/CodeGen/TargetLoweringBase.cpp +++ lib/CodeGen/TargetLoweringBase.cpp @@ -43,6 +43,14 @@ cl::desc("Do not create extra branches to split comparison logic."), cl::Hidden); +// These two command line options are used to override the min/preferred +// function/loop alignment. The value should be specified as log2(bytes). +static cl::opt MinFA("min-func-alignment", cl::init(0), cl::Hidden, + cl::desc("Override the minimimum function alignment")); + +static cl::opt MinLA("min-loop-alignment", cl::init(0), cl::Hidden, + cl::desc("Override the minimimum loop alignment")); + /// InitLibcallNames - Set default libcall names. /// static void InitLibcallNames(const char **Names, const Triple &TT) { @@ -749,7 +757,10 @@ JumpBufAlignment = 0; MinFunctionAlignment = 0; PrefFunctionAlignment = 0; + CLFunctionAlignment = MinFA; + MinLoopAlignment = 0; PrefLoopAlignment = 0; + CLLoopAlignment = MinLA; GatherAllAliasesMaxDepth = 6; MinStackArgumentAlignment = 1; InsertFencesForAtomic = false;