diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-08-21 15:16:25 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-08-21 15:16:25 +0000 |
commit | 707f786cc5c78730bd8009af11a7a7473a699b32 (patch) | |
tree | fd99f1e02874bcdb7018f46e6e95052b4ea32cbf /llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | |
parent | 0707434ce80935c706fb0f3b2c9c9d2907adbcb9 (diff) | |
download | bcm5719-llvm-707f786cc5c78730bd8009af11a7a7473a699b32.tar.gz bcm5719-llvm-707f786cc5c78730bd8009af11a7a7473a699b32.zip |
revert r311333: [LibCallSimplifier] try harder to fold memcmp with constant arguments
We're getting lots of compile-timeout bot failures like:
http://lab.llvm.org:8011/builders/clang-native-arm-lnt/builds/7119
http://lab.llvm.org:8011/builders/clang-cmake-x86_64-avx2-linux
llvm-svn: 311340
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index b2319945a2c..8257dbcf858 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -18,7 +18,6 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/Triple.h" -#include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/OptimizationDiagnosticInfo.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/ValueTracking.h" @@ -752,44 +751,29 @@ Value *LibCallSimplifier::optimizeMemCmp(CallInst *CI, IRBuilder<> &B) { } // memcmp(S1,S2,N/8)==0 -> (*(intN_t*)S1 != *(intN_t*)S2)==0 - // TODO: The case where both inputs are constants does not need to be limited - // to legal integers or equality comparison. See block below this. if (DL.isLegalInteger(Len * 8) && isOnlyUsedInZeroEqualityComparison(CI)) { + IntegerType *IntType = IntegerType::get(CI->getContext(), Len * 8); unsigned PrefAlignment = DL.getPrefTypeAlignment(IntType); - // First, see if we can fold either argument to a constant. - Value *LHSV = nullptr; - if (auto *LHSC = dyn_cast<Constant>(LHS)) { - LHSC = ConstantExpr::getBitCast(LHSC, IntType->getPointerTo()); - LHSV = ConstantFoldLoadFromConstPtr(LHSC, IntType, DL); - } - Value *RHSV = nullptr; - if (auto *RHSC = dyn_cast<Constant>(RHS)) { - RHSC = ConstantExpr::getBitCast(RHSC, IntType->getPointerTo()); - RHSV = ConstantFoldLoadFromConstPtr(RHSC, IntType, DL); - } + if (getKnownAlignment(LHS, DL, CI) >= PrefAlignment && + getKnownAlignment(RHS, DL, CI) >= PrefAlignment) { - // Don't generate unaligned loads. If either source is constant data, - // alignment doesn't matter for that source because there is no load. - if (!LHSV && getKnownAlignment(LHS, DL, CI) >= PrefAlignment) { Type *LHSPtrTy = IntType->getPointerTo(LHS->getType()->getPointerAddressSpace()); - LHSV = B.CreateLoad(B.CreateBitCast(LHS, LHSPtrTy), "lhsv"); - } - - if (!RHSV && getKnownAlignment(RHS, DL, CI) >= PrefAlignment) { Type *RHSPtrTy = IntType->getPointerTo(RHS->getType()->getPointerAddressSpace()); - RHSV = B.CreateLoad(B.CreateBitCast(RHS, RHSPtrTy), "rhsv"); - } - if (LHSV && RHSV) + Value *LHSV = + B.CreateLoad(B.CreateBitCast(LHS, LHSPtrTy, "lhsc"), "lhsv"); + Value *RHSV = + B.CreateLoad(B.CreateBitCast(RHS, RHSPtrTy, "rhsc"), "rhsv"); + return B.CreateZExt(B.CreateICmpNE(LHSV, RHSV), CI->getType(), "memcmp"); + } } - // Constant folding: memcmp(x, y, Len) -> constant (all arguments are const). - // TODO: This is limited to i8 arrays. + // Constant folding: memcmp(x, y, l) -> cnst (all arguments are constant) StringRef LHSStr, RHSStr; if (getConstantStringInfo(LHS, LHSStr) && getConstantStringInfo(RHS, RHSStr)) { |