mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-25 00:29:20 +00:00
Fix a crasher trying to fold each element in a comparison between two vectors
if one of the vectors didn't have elements (such as undef). Fixes PR 6096. Fix an issue in the constant folder where fcmp (<2 x %ty>, <2 x %ty>) would have <2 x i1> type if constant folding was successful and i1 type if it wasn't. This exposed a related issue in the bitcode reader. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94069 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1548b863ce
commit
401f3258f6
@ -1167,7 +1167,7 @@ bool BitcodeReader::ParseConstants() {
|
||||
Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
|
||||
Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
|
||||
|
||||
if (OpTy->isFloatingPoint())
|
||||
if (OpTy->isFPOrFPVector())
|
||||
V = ConstantExpr::getFCmp(Record[3], Op0, Op1);
|
||||
else
|
||||
V = ConstantExpr::getICmp(Record[3], Op0, Op1);
|
||||
|
@ -1673,14 +1673,15 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
|
||||
SmallVector<Constant*, 16> C1Elts, C2Elts;
|
||||
C1->getVectorElements(Context, C1Elts);
|
||||
C2->getVectorElements(Context, C2Elts);
|
||||
if (C1Elts.empty() || C2Elts.empty())
|
||||
return 0;
|
||||
|
||||
// If we can constant fold the comparison of each element, constant fold
|
||||
// the whole vector comparison.
|
||||
SmallVector<Constant*, 4> ResElts;
|
||||
for (unsigned i = 0, e = C1Elts.size(); i != e; ++i) {
|
||||
// Compare the elements, producing an i1 result or constant expr.
|
||||
ResElts.push_back(
|
||||
ConstantExpr::getCompare(pred, C1Elts[i], C2Elts[i]));
|
||||
ResElts.push_back(ConstantExpr::getCompare(pred, C1Elts[i], C2Elts[i]));
|
||||
}
|
||||
return ConstantVector::get(&ResElts[0], ResElts.size());
|
||||
}
|
||||
|
@ -1646,9 +1646,12 @@ ConstantExpr::getICmp(unsigned short pred, Constant* LHS, Constant* RHS) {
|
||||
// Get the key type with both the opcode and predicate
|
||||
const ExprMapKeyType Key(Instruction::ICmp, ArgVec, pred);
|
||||
|
||||
const Type *ResultTy = Type::getInt1Ty(LHS->getContext());
|
||||
if (const VectorType *VT = dyn_cast<VectorType>(LHS->getType()))
|
||||
ResultTy = VectorType::get(ResultTy, VT->getNumElements());
|
||||
|
||||
LLVMContextImpl *pImpl = LHS->getType()->getContext().pImpl;
|
||||
return
|
||||
pImpl->ExprConstants.getOrCreate(Type::getInt1Ty(LHS->getContext()), Key);
|
||||
return pImpl->ExprConstants.getOrCreate(ResultTy, Key);
|
||||
}
|
||||
|
||||
Constant *
|
||||
@ -1667,9 +1670,12 @@ ConstantExpr::getFCmp(unsigned short pred, Constant* LHS, Constant* RHS) {
|
||||
// Get the key type with both the opcode and predicate
|
||||
const ExprMapKeyType Key(Instruction::FCmp, ArgVec, pred);
|
||||
|
||||
const Type *ResultTy = Type::getInt1Ty(LHS->getContext());
|
||||
if (const VectorType *VT = dyn_cast<VectorType>(LHS->getType()))
|
||||
ResultTy = VectorType::get(ResultTy, VT->getNumElements());
|
||||
|
||||
LLVMContextImpl *pImpl = LHS->getType()->getContext().pImpl;
|
||||
return
|
||||
pImpl->ExprConstants.getOrCreate(Type::getInt1Ty(LHS->getContext()), Key);
|
||||
return pImpl->ExprConstants.getOrCreate(ResultTy, Key);
|
||||
}
|
||||
|
||||
Constant *ConstantExpr::getExtractElementTy(const Type *ReqTy, Constant *Val,
|
||||
|
@ -58,3 +58,10 @@
|
||||
|
||||
; CHECK: @T5 = global i1* @A
|
||||
@T5 = global i1* inttoptr (i64 add (i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 192)), i256 192) to i64), i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 192)), i256 128) to i64)) to i1*)
|
||||
|
||||
|
||||
|
||||
; PR6096
|
||||
|
||||
; No check line. This used to crash llvm-as.
|
||||
@T6 = global <2 x i1> fcmp ole (<2 x float> fdiv (<2 x float> undef, <2 x float> <float 1.000000e+00, float 1.000000e+00>), <2 x float> zeroinitializer)
|
||||
|
Loading…
Reference in New Issue
Block a user