Skip to content

Commit f64de79

Browse files
committed
Removed handling of invalid cases
1 parent 77952a5 commit f64de79

File tree

2 files changed

+4
-48
lines changed

2 files changed

+4
-48
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3769,20 +3769,14 @@ static Constant *ConstantFoldFixedVectorCall(
37693769
if (NumElements == VecNumElements && StartingIndex == 0)
37703770
return Vec;
37713771

3772-
const unsigned NonPoisonNumElements =
3773-
std::min(StartingIndex + NumElements, VecNumElements);
3774-
for (unsigned I = StartingIndex; I < NonPoisonNumElements; ++I) {
3772+
for (unsigned I = StartingIndex, E = StartingIndex + NumElements; I < E;
3773+
++I) {
37753774
Constant *Elt = Vec->getAggregateElement(I);
37763775
if (!Elt)
37773776
return nullptr;
37783777
Result[I - StartingIndex] = Elt;
37793778
}
37803779

3781-
// Remaining elements are poison since they are out of bounds.
3782-
for (unsigned I = NonPoisonNumElements, E = StartingIndex + NumElements;
3783-
I < E; ++I)
3784-
Result[I - StartingIndex] = PoisonValue::get(FVTy->getElementType());
3785-
37863780
return ConstantVector::get(Result);
37873781
}
37883782
case Intrinsic::vector_insert: {
@@ -3801,15 +3795,9 @@ static Constant *ConstantFoldFixedVectorCall(
38013795
if (SubVecNumElements == VecNumElements && IdxN == 0)
38023796
return SubVec;
38033797

3804-
// Make sure indices are in the range [0, VecNumElements), otherwise the
3805-
// result is a poison value.
3806-
if (IdxN >= VecNumElements || IdxN + SubVecNumElements > VecNumElements ||
3807-
(IdxN % SubVecNumElements) != 0)
3808-
return PoisonValue::get(FVTy);
3809-
38103798
for (unsigned I = 0; I < VecNumElements; ++I) {
38113799
Constant *Elt;
3812-
if (I >= IdxN && I < IdxN + SubVecNumElements)
3800+
if (I < IdxN + SubVecNumElements)
38133801
Elt = SubVec->getAggregateElement(I - IdxN);
38143802
else
38153803
Elt = Vec->getAggregateElement(I);

llvm/test/Transforms/InstSimplify/ConstProp/vector-calls.ll

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt < %s -passes=instsimplify,verify -disable-verify -S | FileCheck %s
2+
; RUN: opt < %s -passes=instsimplify,verify -S | FileCheck %s
33

44
define <3 x i32> @fold_vector_extract() {
55
; CHECK-LABEL: define <3 x i32> @fold_vector_extract() {
@@ -19,22 +19,6 @@ define <3 x i32> @fold_vector_extract_constexpr() {
1919
ret <3 x i32> %1
2020
}
2121

22-
define <3 x i32> @fold_vector_extract_last_poison() {
23-
; CHECK-LABEL: define <3 x i32> @fold_vector_extract_last_poison() {
24-
; CHECK-NEXT: ret <3 x i32> <i32 6, i32 7, i32 poison>
25-
;
26-
%1 = call <3 x i32> @llvm.vector.extract.v3i32.v8i32(<8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>, i64 6)
27-
ret <3 x i32> %1
28-
}
29-
30-
define <3 x i32> @fold_vector_extract_poison() {
31-
; CHECK-LABEL: define <3 x i32> @fold_vector_extract_poison() {
32-
; CHECK-NEXT: ret <3 x i32> poison
33-
;
34-
%1 = call <3 x i32> @llvm.vector.extract.v3i32.v8i32(<8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>, i64 8)
35-
ret <3 x i32> %1
36-
}
37-
3822
define <8 x i32> @fold_vector_extract_nop() {
3923
; CHECK-LABEL: define <8 x i32> @fold_vector_extract_nop() {
4024
; CHECK-NEXT: ret <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
@@ -59,22 +43,6 @@ define <8 x i32> @fold_vector_insert_nop() {
5943
ret <8 x i32> %1
6044
}
6145

62-
define <8 x i32> @fold_vector_insert_poison_idx_range() {
63-
; CHECK-LABEL: define <8 x i32> @fold_vector_insert_poison_idx_range() {
64-
; CHECK-NEXT: ret <8 x i32> poison
65-
;
66-
%1 = call <8 x i32> @llvm.vector.insert.v8i32(<8 x i32> <i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8>, <6 x i32> <i32 9, i32 10, i32 11, i32 12, i32 13, i32 14>, i64 6)
67-
ret <8 x i32> %1
68-
}
69-
70-
define <8 x i32> @fold_vector_insert_poison_large_idx() {
71-
; CHECK-LABEL: define <8 x i32> @fold_vector_insert_poison_large_idx() {
72-
; CHECK-NEXT: ret <8 x i32> poison
73-
;
74-
%1 = call <8 x i32> @llvm.vector.insert.v8i32(<8 x i32> <i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8>, <6 x i32> <i32 9, i32 10, i32 11, i32 12, i32 13, i32 14>, i64 -2)
75-
ret <8 x i32> %1
76-
}
77-
7846
define <8 x i32> @fold_vector_interleave2() {
7947
; CHECK-LABEL: define <8 x i32> @fold_vector_interleave2() {
8048
; CHECK-NEXT: ret <8 x i32> <i32 1, i32 5, i32 2, i32 6, i32 3, i32 7, i32 4, i32 8>

0 commit comments

Comments
 (0)