diff --git a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp --- a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp +++ b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp @@ -160,6 +160,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/Statistic.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/MemoryBuiltins.h" #include "llvm/Analysis/ScalarEvolution.h" @@ -177,7 +178,6 @@ #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" -#include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/PatternMatch.h" #include "llvm/IR/Type.h" @@ -187,6 +187,7 @@ #include "llvm/Pass.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Scalar.h" @@ -198,6 +199,10 @@ using namespace llvm; using namespace llvm::PatternMatch; +#define DEBUG_TYPE "separate-const-offset-from-gep" + +STATISTIC(NumSplittedGEPs, "Number of splitted GEPs"); + static cl::opt DisableSeparateConstOffsetFromGEP( "disable-separate-const-offset-from-gep", cl::init(false), cl::desc("Do not separate the constant offset from a GEP instruction"), @@ -992,6 +997,8 @@ /*BaseGV=*/nullptr, AccumulativeByteOffset, /*HasBaseReg=*/true, /*Scale=*/0, AddrSpace)) { + LLVM_DEBUG(dbgs() << "Don't optimize. The backend doesn't support the " + "addressing mode\n"); return Changed; } } @@ -1091,6 +1098,8 @@ Instruction *NewGEP = GEP->clone(); NewGEP->insertBefore(GEP); + LLVM_DEBUG(dbgs() << "Created new base GEP " << *NewGEP << "\n"); + // Per ANSI C standard, signed / unsigned = unsigned and signed % unsigned = // unsigned.. Therefore, we cast ElementTypeSizeOfGEP to signed because it is // used with unsigned integers later. @@ -1137,8 +1146,12 @@ } GEP->replaceAllUsesWith(NewGEP); + LLVM_DEBUG(dbgs() << "Replaced GEP " << *GEP << " with new one " << *GEP + << "\n"); GEP->eraseFromParent(); + NumSplittedGEPs++; + return true; }