Support the case when ptr is non-vector whereas idx has vectors
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -1899,10 +1899,15 @@ StateValue GEP::toSMT(State &s) const {
return { ptr.release(), move(non_poison) };
};
- if (auto ptr_aty = ptr->getType().getAsAggregateType()) {
+ if (auto aty = getType().getAsAggregateType()) {
vector<StateValue> vals;
- auto &ptrval = s[*ptr];
- for (unsigned i = 0, e = ptr_aty->numElementsConst(); i != e; ++i) {
+ auto ptrval = s[*ptr];
+ if (!ptr->getType().isVectorType()) {
+ vector<StateValue> ptrvals(aty->numElementsConst(), ptrval);
+ ptrval = getType().getAsAggregateType()->aggregateVals(ptrvals);
+ }
+
+ for (unsigned i = 0, e = aty->numElementsConst(); i != e; ++i) {
vector<pair<unsigned, StateValue>> offsets;
for (auto &[sz, idx] : idxs) {
if (auto idx_aty = idx->getType().getAsAggregateType())
@@ -1910,7 +1915,7 @@ StateValue GEP::toSMT(State &s) const {
else
offsets.emplace_back(sz, s[*idx]);
}
- vals.emplace_back(scalar(ptr_aty->extract(ptrval, i), offsets));
+ vals.emplace_back(scalar(aty->extract(ptrval, i), offsets));
}
return getType().getAsAggregateType()->aggregateVals(vals);
}
@@ -1922,7 +1927,7 @@ StateValue GEP::toSMT(State &s) const {
expr GEP::getTypeConstraints(const Function &f) const {
auto c = Value::getTypeConstraints() &&
- getType() == ptr->getType() &&
+ getType().enforceVectorTypeIff(ptr->getType()) &&
getType().enforcePtrOrVectorType();
for (auto &[sz, idx] : idxs) {
(void)sz;

MODIFY
tests/alive-tv/memory/gep-vector.src.ll
tests/alive-tv/memory/gep-vector.src.ll
@@ -17,3 +17,10 @@ define <2 x i1> @test6b(<2 x i32> %X, <2 x %S*> %P) {
ret <2 x i1> %C
}
+; from Transforms/InstCombine/gep-vector.ll
+@block = global [64 x [8192 x i8]] zeroinitializer, align 1
+
+define <2 x i8*> @vectorindex1() {
+ %1 = getelementptr inbounds [64 x [8192 x i8]], [64 x [8192 x i8]]* @block, i64 0, <2 x i64> <i64 0, i64 1>, i64 8192
+ ret <2 x i8*> %1
+}

MODIFY
tests/alive-tv/memory/gep-vector.tgt.ll
tests/alive-tv/memory/gep-vector.tgt.ll
@@ -12,3 +12,8 @@ define <2 x i1> @test6b(<2 x i32> %X, <2 x %S*> %P) {
ret <2 x i1> %a
}
+@block = global [64 x [8192 x i8]] zeroinitializer, align 1
+
+define <2 x i8*> @vectorindex1() {
+ ret <2 x i8*> getelementptr inbounds ([64 x [8192 x i8]], [64 x [8192 x i8]]* @block, <2 x i64> zeroinitializer, <2 x i64> <i64 1, i64 2>, <2 x i64> zeroinitializer)
+}

Support the case when ptr is non-vector whereas idx has vectors (#234)