[PATCH] D63940: NFC: Pass DataLayout into isBytewiseValue

2019-07-10 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365709: NFC: Pass DataLayout into isBytewiseValue (authored 
by vitalybuka, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D63940?vs=207092=209086#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63940/new/

https://reviews.llvm.org/D63940

Files:
  cfe/trunk/lib/CodeGen/CGDecl.cpp
  llvm/trunk/include/llvm/Analysis/ValueTracking.h
  llvm/trunk/lib/Analysis/ValueTracking.cpp
  llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
  llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Index: llvm/trunk/include/llvm/Analysis/ValueTracking.h
===
--- llvm/trunk/include/llvm/Analysis/ValueTracking.h
+++ llvm/trunk/include/llvm/Analysis/ValueTracking.h
@@ -224,7 +224,7 @@
   /// 0.0 etc. If the value can't be handled with a repeated byte store (e.g.
   /// i16 0x1234), return null. If the value is entirely undef and padding,
   /// return undef.
-  Value *isBytewiseValue(Value *V);
+  Value *isBytewiseValue(Value *V, const DataLayout );
 
   /// Given an aggregrate and an sequence of indices, see if the scalar value
   /// indexed is already around as a register, for example if it were inserted
Index: llvm/trunk/lib/Analysis/ValueTracking.cpp
===
--- llvm/trunk/lib/Analysis/ValueTracking.cpp
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp
@@ -3166,7 +3166,7 @@
   return true;
 }
 
-Value *llvm::isBytewiseValue(Value *V) {
+Value *llvm::isBytewiseValue(Value *V, const DataLayout ) {
 
   // All byte-wide stores are splatable, even of arbitrary variables.
   if (V->getType()->isIntegerTy(8))
@@ -3205,7 +3205,8 @@
 else if (CFP->getType()->isDoubleTy())
   Ty = Type::getInt64Ty(Ctx);
 // Don't handle long double formats, which have strange constraints.
-return Ty ? isBytewiseValue(ConstantExpr::getBitCast(CFP, Ty)) : nullptr;
+return Ty ? isBytewiseValue(ConstantExpr::getBitCast(CFP, Ty), DL)
+  : nullptr;
   }
 
   // We can handle constant integers that are multiple of 8 bits.
@@ -3233,20 +3234,20 @@
   if (ConstantDataSequential *CA = dyn_cast(C)) {
 Value *Val = UndefInt8;
 for (unsigned I = 0, E = CA->getNumElements(); I != E; ++I)
-  if (!(Val = Merge(Val, isBytewiseValue(CA->getElementAsConstant(I)
+  if (!(Val = Merge(Val, isBytewiseValue(CA->getElementAsConstant(I), DL
 return nullptr;
 return Val;
   }
 
   if (isa(C)) {
 Constant *Splat = cast(C)->getSplatValue();
-return Splat ? isBytewiseValue(Splat) : nullptr;
+return Splat ? isBytewiseValue(Splat, DL) : nullptr;
   }
 
   if (isa(C) || isa(C)) {
 Value *Val = UndefInt8;
 for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I)
-  if (!(Val = Merge(Val, isBytewiseValue(C->getOperand(I)
+  if (!(Val = Merge(Val, isBytewiseValue(C->getOperand(I), DL
 return nullptr;
 return Val;
   }
Index: llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===
--- llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -412,7 +412,7 @@
   if (!NextStore->isSimple()) break;
 
   // Check to see if this stored value is of the same byte-splattable value.
-  Value *StoredByte = isBytewiseValue(NextStore->getOperand(0));
+  Value *StoredByte = isBytewiseValue(NextStore->getOperand(0), DL);
   if (isa(ByteVal) && StoredByte)
 ByteVal = StoredByte;
   if (ByteVal != StoredByte)
@@ -749,7 +749,7 @@
   // byte at a time like "0" or "-1" or any width, as well as things like
   // 0xA0A0A0A0 and 0.0.
   auto *V = SI->getOperand(0);
-  if (Value *ByteVal = isBytewiseValue(V)) {
+  if (Value *ByteVal = isBytewiseValue(V, DL)) {
 if (Instruction *I = tryMergingIntoMemset(SI, SI->getPointerOperand(),
   ByteVal)) {
   BBI = I->getIterator(); // Don't invalidate iterator.
@@ -1229,7 +1229,8 @@
   // If copying from a constant, try to turn the memcpy into a memset.
   if (GlobalVariable *GV = dyn_cast(M->getSource()))
 if (GV->isConstant() && GV->hasDefinitiveInitializer())
-  if (Value *ByteVal = isBytewiseValue(GV->getInitializer())) {
+  if (Value *ByteVal = isBytewiseValue(GV->getInitializer(),
+   M->getModule()->getDataLayout())) {
 IRBuilder<> Builder(M);
 Builder.CreateMemSet(M->getRawDest(), ByteVal, M->getLength(),
  M->getDestAlignment(), false);
Index: llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
===
--- llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ 

[PATCH] D63940: [NFC] Pass DataLayout into isBytewiseValue

2019-07-10 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis accepted this revision.
eugenis added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63940/new/

https://reviews.llvm.org/D63940



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63940: [NFC] Pass DataLayout into isBytewiseValue

2019-06-28 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.
vitalybuka added a parent revision: D63854: [NFC] Convert large lambda into 
method.

We will need to handle IntToPtr which I will submit in a separate patch as it's
not going to be NFC.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63940

Files:
  clang/lib/CodeGen/CGDecl.cpp
  llvm/include/llvm/Analysis/ValueTracking.h
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
  llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Index: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===
--- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -412,7 +412,7 @@
   if (!NextStore->isSimple()) break;
 
   // Check to see if this stored value is of the same byte-splattable value.
-  Value *StoredByte = isBytewiseValue(NextStore->getOperand(0));
+  Value *StoredByte = isBytewiseValue(NextStore->getOperand(0), DL);
   if (isa(ByteVal) && StoredByte)
 ByteVal = StoredByte;
   if (ByteVal != StoredByte)
@@ -749,7 +749,7 @@
   // byte at a time like "0" or "-1" or any width, as well as things like
   // 0xA0A0A0A0 and 0.0.
   auto *V = SI->getOperand(0);
-  if (Value *ByteVal = isBytewiseValue(V)) {
+  if (Value *ByteVal = isBytewiseValue(V, DL)) {
 if (Instruction *I = tryMergingIntoMemset(SI, SI->getPointerOperand(),
   ByteVal)) {
   BBI = I->getIterator(); // Don't invalidate iterator.
@@ -1229,7 +1229,8 @@
   // If copying from a constant, try to turn the memcpy into a memset.
   if (GlobalVariable *GV = dyn_cast(M->getSource()))
 if (GV->isConstant() && GV->hasDefinitiveInitializer())
-  if (Value *ByteVal = isBytewiseValue(GV->getInitializer())) {
+  if (Value *ByteVal = isBytewiseValue(GV->getInitializer(),
+   M->getModule()->getDataLayout())) {
 IRBuilder<> Builder(M);
 Builder.CreateMemSet(M->getRawDest(), ByteVal, M->getLength(),
  M->getDestAlignment(), false);
Index: llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
===
--- llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -450,7 +450,7 @@
   // turned into a memset of i8 -1, assuming that all the consecutive bytes
   // are stored.  A store of i32 0x01020304 can never be turned into a memset,
   // but it can be turned into memset_pattern if the target supports it.
-  Value *SplatValue = isBytewiseValue(StoredVal);
+  Value *SplatValue = isBytewiseValue(StoredVal, *DL);
   Constant *PatternValue = nullptr;
 
   // Note: memset and memset_pattern on unordered-atomic is yet not supported
@@ -627,7 +627,7 @@
 Constant *FirstPatternValue = nullptr;
 
 if (For == ForMemset::Yes)
-  FirstSplatValue = isBytewiseValue(FirstStoredVal);
+  FirstSplatValue = isBytewiseValue(FirstStoredVal, *DL);
 else
   FirstPatternValue = getMemSetPatternValue(FirstStoredVal, DL);
 
@@ -660,7 +660,7 @@
   Constant *SecondPatternValue = nullptr;
 
   if (For == ForMemset::Yes)
-SecondSplatValue = isBytewiseValue(SecondStoredVal);
+SecondSplatValue = isBytewiseValue(SecondStoredVal, *DL);
   else
 SecondPatternValue = getMemSetPatternValue(SecondStoredVal, DL);
 
@@ -880,7 +880,7 @@
 Value *StoredVal, Instruction *TheStore,
 SmallPtrSetImpl , const SCEVAddRecExpr *Ev,
 const SCEV *BECount, bool NegStride, bool IsLoopMemset) {
-  Value *SplatValue = isBytewiseValue(StoredVal);
+  Value *SplatValue = isBytewiseValue(StoredVal, *DL);
   Constant *PatternValue = nullptr;
 
   if (!SplatValue)
Index: llvm/lib/Analysis/ValueTracking.cpp
===
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -3166,7 +3166,7 @@
   return true;
 }
 
-Value *llvm::isBytewiseValue(Value *V) {
+Value *llvm::isBytewiseValue(Value *V, const DataLayout ) {
 
   // All byte-wide stores are splatable, even of arbitrary variables.
   if (V->getType()->isIntegerTy(8))
@@ -3205,7 +3205,8 @@
 else if (CFP->getType()->isDoubleTy())
   Ty = Type::getInt64Ty(Ctx);
 // Don't handle long double formats, which have strange constraints.
-return Ty ? isBytewiseValue(ConstantExpr::getBitCast(CFP, Ty)) : nullptr;
+return Ty ? isBytewiseValue(ConstantExpr::getBitCast(CFP, Ty), DL)
+  : nullptr;
   }
 
   // We can handle constant integers that are multiple of 8 bits.
@@ -3233,20 +3234,20 @@
   if (ConstantDataSequential *CA = dyn_cast(C)) {
 Value *Val = UndefInt8;
 for (unsigned I = 0, E = CA->getNumElements(); I != E; ++I)
-  if