[llvm-commits] [llvm] r148806 - in /llvm/trunk/lib/Transforms/InstCombine: InstCombineSimplifyDemanded.cpp InstCombineVectorOps.cpp
Chris Lattner
sabre at nondot.org
Tue Jan 24 06:31:22 PST 2012
Author: lattner
Date: Tue Jan 24 08:31:22 2012
New Revision: 148806
URL: http://llvm.org/viewvc/llvm-project?rev=148806&view=rev
Log:
basic instcombine support for CDS.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp?rev=148806&r1=148805&r2=148806&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp Tue Jan 24 08:31:22 2012
@@ -855,23 +855,36 @@
return NewCP != CV ? NewCP : 0;
}
- if (isa<ConstantAggregateZero>(V)) {
- // Simplify the CAZ to a ConstantVector where the non-demanded elements are
- // set to undef.
+ if (ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(V)) {
+ // Check if this is identity. If so, return 0 since we are not simplifying
+ // anything.
+ if (DemandedElts.isAllOnesValue())
+ return 0;
+
+ // Simplify to a ConstantVector where the non-demanded elements are undef.
+ Constant *Undef = UndefValue::get(CDV->getElementType());
+ SmallVector<Constant*, 16> Elts;
+ for (unsigned i = 0; i != VWidth; ++i)
+ Elts.push_back(DemandedElts[i] ? CDV->getElementAsConstant(i) : Undef);
+ UndefElts = DemandedElts ^ EltMask;
+ return ConstantVector::get(Elts);
+
+ }
+
+ if (ConstantAggregateZero *CAZ = dyn_cast<ConstantAggregateZero>(V)) {
// Check if this is identity. If so, return 0 since we are not simplifying
// anything.
if (DemandedElts.isAllOnesValue())
return 0;
- Type *EltTy = cast<VectorType>(V->getType())->getElementType();
- Constant *Zero = Constant::getNullValue(EltTy);
- Constant *Undef = UndefValue::get(EltTy);
- std::vector<Constant*> Elts;
- for (unsigned i = 0; i != VWidth; ++i) {
- Constant *Elt = DemandedElts[i] ? Zero : Undef;
- Elts.push_back(Elt);
- }
+ // Simplify the CAZ to a ConstantVector where the non-demanded elements are
+ // set to undef.
+ Constant *Zero = CAZ->getSequentialElement();
+ Constant *Undef = UndefValue::get(Zero->getType());
+ SmallVector<Constant*, 16> Elts;
+ for (unsigned i = 0; i != VWidth; ++i)
+ Elts.push_back(DemandedElts[i] ? Zero : Undef);
UndefElts = DemandedElts ^ EltMask;
return ConstantVector::get(Elts);
}
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp?rev=148806&r1=148805&r2=148806&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp Tue Jan 24 08:31:22 2012
@@ -16,7 +16,8 @@
using namespace llvm;
/// CheapToScalarize - Return true if the value is cheaper to scalarize than it
-/// is to leave as a vector operation.
+/// is to leave as a vector operation. isConstant indicates whether we're
+/// extracting one known element. If false we're extracting a variable index.
static bool CheapToScalarize(Value *V, bool isConstant) {
if (isa<ConstantAggregateZero>(V))
return true;
@@ -335,10 +336,14 @@
if (isa<UndefValue>(V)) {
Mask.assign(NumElts, UndefValue::get(Type::getInt32Ty(V->getContext())));
return V;
- } else if (isa<ConstantAggregateZero>(V)) {
+ }
+
+ if (isa<ConstantAggregateZero>(V)) {
Mask.assign(NumElts, ConstantInt::get(Type::getInt32Ty(V->getContext()),0));
return V;
- } else if (InsertElementInst *IEI = dyn_cast<InsertElementInst>(V)) {
+ }
+
+ if (InsertElementInst *IEI = dyn_cast<InsertElementInst>(V)) {
// If this is an insert of an extract from some other vector, include it.
Value *VecOp = IEI->getOperand(0);
Value *ScalarOp = IEI->getOperand(1);
More information about the llvm-commits
mailing list