Fix PR2112: don't run loop aligner if target doesn't have a TargetLowering object.
llvm-svn: 47755
diff --git a/llvm/lib/CodeGen/LoopAligner.cpp b/llvm/lib/CodeGen/LoopAligner.cpp
index a40bb50..1888391 100644
--- a/llvm/lib/CodeGen/LoopAligner.cpp
+++ b/llvm/lib/CodeGen/LoopAligner.cpp
@@ -24,8 +24,6 @@
namespace {
class LoopAligner : public MachineFunctionPass {
- const TargetLowering *TLI;
-
public:
static char ID;
LoopAligner() : MachineFunctionPass((intptr_t)&ID) {}
@@ -51,7 +49,11 @@
if (MLI->begin() == MLI->end())
return false; // No loops.
- unsigned Align = MF.getTarget().getTargetLowering()->getPrefLoopAlignment();
+ const TargetLowering *TLI = MF.getTarget().getTargetLowering();
+ if (!TLI)
+ return false;
+
+ unsigned Align = TLI->getPrefLoopAlignment();
if (!Align)
return false; // Don't care about loop alignment.