@@ -11640,13 +11640,14 @@ class BoUpSLP::ShuffleInstructionBuilder final : public BaseShuffleAnalysis {
11640
11640
11641
11641
/// Cast value \p V to the vector type with the same number of elements, but
11642
11642
/// the base type \p ScalarTy.
11643
- Value *castToScalarTyElem(Value *V) {
11643
+ Value *castToScalarTyElem(Value *V,
11644
+ std::optional<bool> IsSigned = std::nullopt) {
11644
11645
auto *VecTy = cast<VectorType>(V->getType());
11645
11646
if (VecTy->getElementType() == ScalarTy)
11646
11647
return V;
11647
11648
return Builder.CreateIntCast(
11648
11649
V, VectorType::get(ScalarTy, VecTy->getElementCount()),
11649
- !isKnownNonNegative(V, SimplifyQuery(*R.DL)));
11650
+ IsSigned ? *IsSigned : !isKnownNonNegative(V, SimplifyQuery(*R.DL)));
11650
11651
}
11651
11652
11652
11653
public:
@@ -11795,12 +11796,30 @@ class BoUpSLP::ShuffleInstructionBuilder final : public BaseShuffleAnalysis {
11795
11796
/// Adds 2 input vectors (in form of tree entries) and the mask for their
11796
11797
/// shuffling.
11797
11798
void add(const TreeEntry &E1, const TreeEntry &E2, ArrayRef<int> Mask) {
11798
- add(E1.VectorizedValue, E2.VectorizedValue, Mask);
11799
+ Value *V1 = E1.VectorizedValue;
11800
+ if (V1->getType()->isIntOrIntVectorTy())
11801
+ V1 = castToScalarTyElem(V1, all_of(E1.Scalars, [&](Value *V) {
11802
+ return !isKnownNonNegative(
11803
+ V, SimplifyQuery(*R.DL));
11804
+ }));
11805
+ Value *V2 = E2.VectorizedValue;
11806
+ if (V2->getType()->isIntOrIntVectorTy())
11807
+ V2 = castToScalarTyElem(V2, all_of(E2.Scalars, [&](Value *V) {
11808
+ return !isKnownNonNegative(
11809
+ V, SimplifyQuery(*R.DL));
11810
+ }));
11811
+ add(V1, V2, Mask);
11799
11812
}
11800
11813
/// Adds single input vector (in form of tree entry) and the mask for its
11801
11814
/// shuffling.
11802
11815
void add(const TreeEntry &E1, ArrayRef<int> Mask) {
11803
- add(E1.VectorizedValue, Mask);
11816
+ Value *V1 = E1.VectorizedValue;
11817
+ if (V1->getType()->isIntOrIntVectorTy())
11818
+ V1 = castToScalarTyElem(V1, all_of(E1.Scalars, [&](Value *V) {
11819
+ return !isKnownNonNegative(
11820
+ V, SimplifyQuery(*R.DL));
11821
+ }));
11822
+ add(V1, Mask);
11804
11823
}
11805
11824
/// Adds 2 input vectors and the mask for their shuffling.
11806
11825
void add(Value *V1, Value *V2, ArrayRef<int> Mask) {
0 commit comments