diff options
| author | NAKAMURA Takumi <geek4civic@gmail.com> | 2012-04-27 07:59:20 +0000 |
|---|---|---|
| committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2012-04-27 07:59:20 +0000 |
| commit | 6008dfdb70f3a13b56a5c4ff60bd54435f92b135 (patch) | |
| tree | 7a4380ac82bb0bd6c5a847817bceb6f8b48f6f72 /llvm/lib/VMCore | |
| parent | a1259778b4a2ddd6b2dc1ad9909bdcd152e426b8 (diff) | |
| download | bcm5719-llvm-6008dfdb70f3a13b56a5c4ff60bd54435f92b135.tar.gz bcm5719-llvm-6008dfdb70f3a13b56a5c4ff60bd54435f92b135.zip | |
Revert r155682, "Use ConstantExpr::getExtractElement when constant-folding vectors"
It broke stage2 build. stage1/clang sometimes crashed.
llvm-svn: 155699
Diffstat (limited to 'llvm/lib/VMCore')
| -rw-r--r-- | llvm/lib/VMCore/ConstantFold.cpp | 65 |
1 files changed, 28 insertions, 37 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp index a4ffddb5c4b..9b1c756b7de 100644 --- a/llvm/lib/VMCore/ConstantFold.cpp +++ b/llvm/lib/VMCore/ConstantFold.cpp @@ -55,12 +55,13 @@ static Constant *BitCastConstantVector(Constant *CV, VectorType *DstTy) { Type *DstEltTy = DstTy->getElementType(); + // Check to verify that all elements of the input are simple. SmallVector<Constant*, 16> Result; - Type *Ty = IntegerType::get(CV->getContext(), 32); for (unsigned i = 0; i != NumElts; ++i) { - Constant *C = - ConstantExpr::getExtractElement(CV, ConstantInt::get(Ty, i)); + Constant *C = CV->getAggregateElement(i); + if (C == 0) return 0; C = ConstantExpr::getBitCast(C, DstEltTy); + if (isa<ConstantExpr>(C)) return 0; Result.push_back(C); } @@ -552,12 +553,9 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V, SmallVector<Constant*, 16> res; VectorType *DestVecTy = cast<VectorType>(DestTy); Type *DstEltTy = DestVecTy->getElementType(); - Type *Ty = IntegerType::get(V->getContext(), 32); - for (unsigned i = 0, e = V->getType()->getVectorNumElements(); i != e; ++i) { - Constant *C = - ConstantExpr::getExtractElement(V, ConstantInt::get(Ty, i)); - res.push_back(ConstantExpr::getCast(opc, C, DstEltTy)); - } + for (unsigned i = 0, e = V->getType()->getVectorNumElements(); i != e; ++i) + res.push_back(ConstantExpr::getCast(opc, + V->getAggregateElement(i), DstEltTy)); return ConstantVector::get(res); } @@ -698,13 +696,12 @@ Constant *llvm::ConstantFoldSelectInstruction(Constant *Cond, // If the condition is a vector constant, fold the result elementwise. if (ConstantVector *CondV = dyn_cast<ConstantVector>(Cond)) { SmallVector<Constant*, 16> Result; - Type *Ty = IntegerType::get(CondV->getContext(), 32); for (unsigned i = 0, e = V1->getType()->getVectorNumElements(); i != e;++i){ ConstantInt *Cond = dyn_cast<ConstantInt>(CondV->getOperand(i)); if (Cond == 0) break; - Constant *V = Cond->isNullValue() ? V2 : V1; - Constant *Res = ConstantExpr::getExtractElement(V, ConstantInt::get(Ty, i)); + Constant *Res = (Cond->getZExtValue() ? V1 : V2)->getAggregateElement(i); + if (Res == 0) break; Result.push_back(Res); } @@ -763,16 +760,16 @@ Constant *llvm::ConstantFoldInsertElementInstruction(Constant *Val, const APInt &IdxVal = CIdx->getValue(); SmallVector<Constant*, 16> Result; - Type *Ty = IntegerType::get(Val->getContext(), 32); for (unsigned i = 0, e = Val->getType()->getVectorNumElements(); i != e; ++i){ if (i == IdxVal) { Result.push_back(Elt); continue; } - Constant *C = - ConstantExpr::getExtractElement(Val, ConstantInt::get(Ty, i)); - Result.push_back(C); + if (Constant *C = Val->getAggregateElement(i)) + Result.push_back(C); + else + return 0; } return ConstantVector::get(Result); @@ -804,15 +801,11 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *InElt; if (unsigned(Elt) >= SrcNumElts*2) InElt = UndefValue::get(EltTy); - else if (unsigned(Elt) >= SrcNumElts) { - Type *Ty = IntegerType::get(V2->getContext(), 32); - InElt = - ConstantExpr::getExtractElement(V2, - ConstantInt::get(Ty, Elt - SrcNumElts)); - } else { - Type *Ty = IntegerType::get(V1->getContext(), 32); - InElt = ConstantExpr::getExtractElement(V1, ConstantInt::get(Ty, Elt)); - } + else if (unsigned(Elt) >= SrcNumElts) + InElt = V2->getAggregateElement(Elt - SrcNumElts); + else + InElt = V1->getAggregateElement(Elt); + if (InElt == 0) return 0; Result.push_back(InElt); } @@ -1137,17 +1130,16 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, } else if (VectorType *VTy = dyn_cast<VectorType>(C1->getType())) { // Perform elementwise folding. SmallVector<Constant*, 16> Result; - Type *Ty = IntegerType::get(VTy->getContext(), 32); for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - Constant *LHS = - ConstantExpr::getExtractElement(C1, ConstantInt::get(Ty, i)); - Constant *RHS = - ConstantExpr::getExtractElement(C2, ConstantInt::get(Ty, i)); + Constant *LHS = C1->getAggregateElement(i); + Constant *RHS = C2->getAggregateElement(i); + if (LHS == 0 || RHS == 0) break; Result.push_back(ConstantExpr::get(Opcode, LHS, RHS)); } - return ConstantVector::get(Result); + if (Result.size() == VTy->getNumElements()) + return ConstantVector::get(Result); } if (ConstantExpr *CE1 = dyn_cast<ConstantExpr>(C1)) { @@ -1705,18 +1697,17 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred, // If we can constant fold the comparison of each element, constant fold // the whole vector comparison. SmallVector<Constant*, 4> ResElts; - Type *Ty = IntegerType::get(C1->getContext(), 32); // Compare the elements, producing an i1 result or constant expr. for (unsigned i = 0, e = C1->getType()->getVectorNumElements(); i != e;++i){ - Constant *C1E = - ConstantExpr::getExtractElement(C1, ConstantInt::get(Ty, i)); - Constant *C2E = - ConstantExpr::getExtractElement(C2, ConstantInt::get(Ty, i)); + Constant *C1E = C1->getAggregateElement(i); + Constant *C2E = C2->getAggregateElement(i); + if (C1E == 0 || C2E == 0) break; ResElts.push_back(ConstantExpr::getCompare(pred, C1E, C2E)); } - return ConstantVector::get(ResElts); + if (ResElts.size() == C1->getType()->getVectorNumElements()) + return ConstantVector::get(ResElts); } if (C1->getType()->isFloatingPointTy()) { |

