mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-10-04 04:19:25 +00:00
Fold vector selects with undef elements in the condition. Fixes PR18319.
Patch by Ilia Filippov! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198267 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -705,12 +705,21 @@ Constant *llvm::ConstantFoldSelectInstruction(Constant *Cond,
|
|||||||
SmallVector<Constant*, 16> Result;
|
SmallVector<Constant*, 16> Result;
|
||||||
Type *Ty = IntegerType::get(CondV->getContext(), 32);
|
Type *Ty = IntegerType::get(CondV->getContext(), 32);
|
||||||
for (unsigned i = 0, e = V1->getType()->getVectorNumElements(); i != e;++i){
|
for (unsigned i = 0, e = V1->getType()->getVectorNumElements(); i != e;++i){
|
||||||
ConstantInt *Cond = dyn_cast<ConstantInt>(CondV->getOperand(i));
|
Constant *V;
|
||||||
if (Cond == 0) break;
|
Constant *V1Element = ConstantExpr::getExtractElement(V1,
|
||||||
|
ConstantInt::get(Ty, i));
|
||||||
Constant *V = Cond->isNullValue() ? V2 : V1;
|
Constant *V2Element = ConstantExpr::getExtractElement(V2,
|
||||||
Constant *Res = ConstantExpr::getExtractElement(V, ConstantInt::get(Ty, i));
|
ConstantInt::get(Ty, i));
|
||||||
Result.push_back(Res);
|
Constant *Cond = dyn_cast<Constant>(CondV->getOperand(i));
|
||||||
|
if (V1Element == V2Element) {
|
||||||
|
V = V1Element;
|
||||||
|
} else if (isa<UndefValue>(Cond)) {
|
||||||
|
V = isa<UndefValue>(V1Element) ? V1Element : V2Element;
|
||||||
|
} else {
|
||||||
|
if (!isa<ConstantInt>(Cond)) break;
|
||||||
|
V = Cond->isNullValue() ? V2Element : V1Element;
|
||||||
|
}
|
||||||
|
Result.push_back(V);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we were able to build the vector, return it.
|
// If we were able to build the vector, return it.
|
||||||
|
8
test/Assembler/ConstantExprFoldSelect.ll
Normal file
8
test/Assembler/ConstantExprFoldSelect.ll
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
; RUN: llvm-as < %s | llvm-dis | FileCheck %s
|
||||||
|
; PR18319
|
||||||
|
|
||||||
|
define void @function() {
|
||||||
|
%c = trunc <4 x i16> select (<4 x i1> <i1 undef, i1 undef, i1 false, i1 true>, <4 x i16> <i16 undef, i16 2, i16 3, i16 4>, <4 x i16> <i16 -1, i16 -2, i16 -3, i16 -4>) to <4 x i8>
|
||||||
|
; CHECK: <i16 undef, i16 -2, i16 -3, i16 4>
|
||||||
|
ret void
|
||||||
|
}
|
@@ -5,5 +5,5 @@ define <2 x i32> @main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
; CHECK: define <2 x i32> @main() {
|
; CHECK: define <2 x i32> @main() {
|
||||||
; CHECK: ret <2 x i32> select (<2 x i1> <i1 false, i1 undef>, <2 x i32> zeroinitializer, <2 x i32> <i32 0, i32 undef>)
|
; CHECK: ret <2 x i32> <i32 0, i32 undef>
|
||||||
; CHECK: }
|
; CHECK: }
|
||||||
|
Reference in New Issue
Block a user