mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-27 13:30:05 +00:00
Fix a bunch of bugs handling vector compare constant expressions, fixing
PR2317. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53544 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
071aade5f0
commit
bbedb0e408
@ -730,7 +730,8 @@ bool ConstantExpr::isCast() const {
|
||||
}
|
||||
|
||||
bool ConstantExpr::isCompare() const {
|
||||
return getOpcode() == Instruction::ICmp || getOpcode() == Instruction::FCmp;
|
||||
return getOpcode() == Instruction::ICmp || getOpcode() == Instruction::FCmp ||
|
||||
getOpcode() == Instruction::VICmp || getOpcode() == Instruction::VFCmp;
|
||||
}
|
||||
|
||||
bool ConstantExpr::hasIndices() const {
|
||||
@ -2201,9 +2202,8 @@ ConstantExpr::getFCmp(unsigned short pred, Constant* LHS, Constant* RHS) {
|
||||
|
||||
Constant *
|
||||
ConstantExpr::getVICmp(unsigned short pred, Constant* LHS, Constant* RHS) {
|
||||
assert(isa<VectorType>(LHS->getType()) &&
|
||||
assert(isa<VectorType>(LHS->getType()) && LHS->getType() == RHS->getType() &&
|
||||
"Tried to create vicmp operation on non-vector type!");
|
||||
assert(LHS->getType() == RHS->getType());
|
||||
assert(pred >= ICmpInst::FIRST_ICMP_PREDICATE &&
|
||||
pred <= ICmpInst::LAST_ICMP_PREDICATE && "Invalid VICmp Predicate");
|
||||
|
||||
@ -2211,23 +2211,30 @@ ConstantExpr::getVICmp(unsigned short pred, Constant* LHS, Constant* RHS) {
|
||||
const Type *EltTy = VTy->getElementType();
|
||||
unsigned NumElts = VTy->getNumElements();
|
||||
|
||||
SmallVector<Constant *, 16> Elts;
|
||||
for (unsigned i = 0; i != NumElts; ++i) {
|
||||
Constant *FC = ConstantFoldCompareInstruction(pred, LHS->getOperand(i),
|
||||
RHS->getOperand(i));
|
||||
if (ConstantInt *FCI = dyn_cast_or_null<ConstantInt>(FC)) {
|
||||
if (FCI->getZExtValue())
|
||||
Elts.push_back(ConstantInt::getAllOnesValue(EltTy));
|
||||
else
|
||||
Elts.push_back(ConstantInt::get(EltTy, 0ULL));
|
||||
} else if (FC && isa<UndefValue>(FC)) {
|
||||
Elts.push_back(UndefValue::get(EltTy));
|
||||
} else {
|
||||
break;
|
||||
// See if we can fold the element-wise comparison of the LHS and RHS.
|
||||
SmallVector<Constant *, 16> LHSElts, RHSElts;
|
||||
LHS->getVectorElements(LHSElts);
|
||||
RHS->getVectorElements(RHSElts);
|
||||
|
||||
if (!LHSElts.empty() && !RHSElts.empty()) {
|
||||
SmallVector<Constant *, 16> Elts;
|
||||
for (unsigned i = 0; i != NumElts; ++i) {
|
||||
Constant *FC = ConstantFoldCompareInstruction(pred, LHSElts[i],
|
||||
RHSElts[i]);
|
||||
if (ConstantInt *FCI = dyn_cast_or_null<ConstantInt>(FC)) {
|
||||
if (FCI->getZExtValue())
|
||||
Elts.push_back(ConstantInt::getAllOnesValue(EltTy));
|
||||
else
|
||||
Elts.push_back(ConstantInt::get(EltTy, 0ULL));
|
||||
} else if (FC && isa<UndefValue>(FC)) {
|
||||
Elts.push_back(UndefValue::get(EltTy));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Elts.size() == NumElts)
|
||||
return ConstantVector::get(&Elts[0], Elts.size());
|
||||
}
|
||||
if (Elts.size() == NumElts)
|
||||
return ConstantVector::get(&Elts[0], Elts.size());
|
||||
|
||||
// Look up the constant in the table first to ensure uniqueness
|
||||
std::vector<Constant*> ArgVec;
|
||||
@ -2251,23 +2258,30 @@ ConstantExpr::getVFCmp(unsigned short pred, Constant* LHS, Constant* RHS) {
|
||||
const Type *REltTy = IntegerType::get(EltTy->getPrimitiveSizeInBits());
|
||||
const Type *ResultTy = VectorType::get(REltTy, NumElts);
|
||||
|
||||
SmallVector<Constant *, 16> Elts;
|
||||
for (unsigned i = 0; i != NumElts; ++i) {
|
||||
Constant *FC = ConstantFoldCompareInstruction(pred, LHS->getOperand(i),
|
||||
RHS->getOperand(i));
|
||||
if (ConstantInt *FCI = dyn_cast_or_null<ConstantInt>(FC)) {
|
||||
if (FCI->getZExtValue())
|
||||
Elts.push_back(ConstantInt::getAllOnesValue(REltTy));
|
||||
else
|
||||
Elts.push_back(ConstantInt::get(REltTy, 0ULL));
|
||||
} else if (FC && isa<UndefValue>(FC)) {
|
||||
Elts.push_back(UndefValue::get(REltTy));
|
||||
} else {
|
||||
break;
|
||||
// See if we can fold the element-wise comparison of the LHS and RHS.
|
||||
SmallVector<Constant *, 16> LHSElts, RHSElts;
|
||||
LHS->getVectorElements(LHSElts);
|
||||
RHS->getVectorElements(RHSElts);
|
||||
|
||||
if (!LHSElts.empty() && !RHSElts.empty()) {
|
||||
SmallVector<Constant *, 16> Elts;
|
||||
for (unsigned i = 0; i != NumElts; ++i) {
|
||||
Constant *FC = ConstantFoldCompareInstruction(pred, LHSElts[i],
|
||||
RHSElts[i]);
|
||||
if (ConstantInt *FCI = dyn_cast_or_null<ConstantInt>(FC)) {
|
||||
if (FCI->getZExtValue())
|
||||
Elts.push_back(ConstantInt::getAllOnesValue(REltTy));
|
||||
else
|
||||
Elts.push_back(ConstantInt::get(REltTy, 0ULL));
|
||||
} else if (FC && isa<UndefValue>(FC)) {
|
||||
Elts.push_back(UndefValue::get(REltTy));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Elts.size() == NumElts)
|
||||
return ConstantVector::get(&Elts[0], Elts.size());
|
||||
}
|
||||
if (Elts.size() == NumElts)
|
||||
return ConstantVector::get(&Elts[0], Elts.size());
|
||||
|
||||
// Look up the constant in the table first to ensure uniqueness
|
||||
std::vector<Constant*> ArgVec;
|
||||
@ -2683,8 +2697,14 @@ void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV,
|
||||
if (C2 == From) C2 = To;
|
||||
if (getOpcode() == Instruction::ICmp)
|
||||
Replacement = ConstantExpr::getICmp(getPredicate(), C1, C2);
|
||||
else
|
||||
else if (getOpcode() == Instruction::FCmp)
|
||||
Replacement = ConstantExpr::getFCmp(getPredicate(), C1, C2);
|
||||
else if (getOpcode() == Instruction::VICmp)
|
||||
Replacement = ConstantExpr::getVICmp(getPredicate(), C1, C2);
|
||||
else {
|
||||
assert(getOpcode() == Instruction::VFCmp);
|
||||
Replacement = ConstantExpr::getVFCmp(getPredicate(), C1, C2);
|
||||
}
|
||||
} else if (getNumOperands() == 2) {
|
||||
Constant *C1 = getOperand(0);
|
||||
Constant *C2 = getOperand(1);
|
||||
|
16
test/Assembler/vector-cmp.ll
Normal file
16
test/Assembler/vector-cmp.ll
Normal file
@ -0,0 +1,16 @@
|
||||
; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | grep {global.*vicmp slt}
|
||||
; PR2317
|
||||
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
|
||||
target triple = "i686-apple-darwin9.2.2"
|
||||
|
||||
define <4 x i32> @foo(<4 x float> %a, <4 x float> %b) nounwind {
|
||||
entry:
|
||||
%cmp = vfcmp olt <4 x float> %a, %b ; <4 x i32> [#uses=1]
|
||||
ret <4 x i32> %cmp
|
||||
}
|
||||
|
||||
global <4 x i32> vicmp slt ( <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32> <i32 1, i32 2, i32 1, i32 2> ) ;
|
||||
|
||||
@B = external global i32;
|
||||
|
||||
global <4 x i32> vicmp slt ( <4 x i32> <i32 ptrtoint (i32 * @B to i32), i32 1, i32 1, i32 1>, <4 x i32> <i32 1, i32 2, i32 1, i32 2> ) ;
|
Loading…
Reference in New Issue
Block a user