@@ -269,7 +269,7 @@ Instruction *InstCombinerImpl::commonCastTransforms(CastInst &CI) {
269269 // cast (shuffle X, Mask) --> shuffle (cast X), Mask
270270 Value *X;
271271 ArrayRef<int > Mask;
272- if (match (Src, m_OneUse (m_Shuffle (m_Value (X), m_Undef (), m_Mask (Mask))))) {
272+ if (match (Src, m_OneUse (m_Shuffle (m_Value (X), m_Poison (), m_Mask (Mask))))) {
273273 // TODO: Allow scalable vectors?
274274 auto *SrcTy = dyn_cast<FixedVectorType>(X->getType ());
275275 auto *DestTy = dyn_cast<FixedVectorType>(Ty);
@@ -977,25 +977,26 @@ Instruction *InstCombinerImpl::narrowBinOp(TruncInst &Trunc) {
977977// / creating a shuffle type that targets may not be able to lower effectively.
978978static Instruction *shrinkSplatShuffle (TruncInst &Trunc,
979979 InstCombiner::BuilderTy &Builder) {
980- auto *Shuf = dyn_cast<ShuffleVectorInst>(Trunc.getOperand (0 ));
981- if (Shuf && Shuf->hasOneUse () && match (Shuf->getOperand (1 ), m_Undef ()) &&
982- all_equal (Shuf->getShuffleMask ()) &&
983- ElementCount::isKnownGE (Shuf->getType ()->getElementCount (),
984- cast<VectorType>(Shuf->getOperand (0 )->getType ())
985- ->getElementCount ())) {
986- // trunc (shuf X, Undef, SplatMask) --> shuf (trunc X), Poison, SplatMask
987- // trunc (shuf X, Poison, SplatMask) --> shuf (trunc X), Poison, SplatMask
988- Type *NewTruncTy = Shuf->getOperand (0 )->getType ()->getWithNewType (
989- Trunc.getType ()->getScalarType ());
990- Value *NarrowOp = Builder.CreateTrunc (Shuf->getOperand (0 ), NewTruncTy);
991- return new ShuffleVectorInst (NarrowOp, Shuf->getShuffleMask ());
980+ Value *Shuf = Trunc.getOperand (0 ), *ShufVec;
981+ ArrayRef<int > SplatMask;
982+ if (match (Shuf, m_OneUse (m_Shuffle (m_Value (ShufVec), m_Poison (),
983+ m_Mask (SplatMask)))) &&
984+ match (SplatMask, m_SplatMask ()) &&
985+ ElementCount::isKnownGE (
986+ cast<VectorType>(Shuf->getType ())->getElementCount (),
987+ cast<VectorType>(ShufVec->getType ())->getElementCount ())) {
988+ // trunc (shuf X, poison, SplatMask) --> shuf (trunc X), poison, SplatMask
989+ Type *NewTruncTy =
990+ ShufVec->getType ()->getWithNewType (Trunc.getType ()->getScalarType ());
991+ Value *NarrowOp = Builder.CreateTrunc (ShufVec, NewTruncTy);
992+ return new ShuffleVectorInst (NarrowOp, SplatMask);
992993 }
993994
994995 return nullptr ;
995996}
996997
997998// / Try to narrow the width of an insert element. This could be generalized for
998- // / any vector constant, but we limit the transform to insertion into undef to
999+ // / any vector constant, but we limit the transform to insertion into poison to
9991000// / avoid potential backend problems from unsupported insertion widths. This
10001001// / could also be extended to handle the case of inserting a scalar constant
10011002// / into a vector variable.
@@ -1005,22 +1006,15 @@ static Instruction *shrinkInsertElt(CastInst &Trunc,
10051006 assert ((Opcode == Instruction::Trunc || Opcode == Instruction::FPTrunc) &&
10061007 " Unexpected instruction for shrinking" );
10071008
1008- auto *InsElt = dyn_cast<InsertElementInst>(Trunc.getOperand (0 ));
1009- if (!InsElt || !InsElt->hasOneUse ())
1010- return nullptr ;
1011-
1012- Type *DestTy = Trunc.getType ();
1013- Type *DestScalarTy = DestTy->getScalarType ();
1014- Value *VecOp = InsElt->getOperand (0 );
1015- Value *ScalarOp = InsElt->getOperand (1 );
1016- Value *Index = InsElt->getOperand (2 );
1017-
1018- if (match (VecOp, m_Undef ())) {
1019- // trunc (inselt undef, X, Index) --> inselt undef, (trunc X), Index
1020- // fptrunc (inselt undef, X, Index) --> inselt undef, (fptrunc X), Index
1021- UndefValue *NarrowUndef = UndefValue::get (DestTy);
1022- Value *NarrowOp = Builder.CreateCast (Opcode, ScalarOp, DestScalarTy);
1023- return InsertElementInst::Create (NarrowUndef, NarrowOp, Index);
1009+ Value *Elt, *Index;
1010+ if (match (Trunc.getOperand (0 ),
1011+ m_OneUse (m_InsertElt (m_Poison (), m_Value (Elt), m_Value (Index))))) {
1012+ // trunc (inselt poison, X, Index) --> inselt poison, (trunc X), Index
1013+ // fptrunc (inselt poison, X, Index) --> inselt poison, (fptrunc X), Index
1014+ auto *NarrowPoison = PoisonValue::get (Trunc.getType ());
1015+ Value *NarrowOp =
1016+ Builder.CreateCast (Opcode, Elt, Trunc.getType ()->getScalarType ());
1017+ return InsertElementInst::Create (NarrowPoison, NarrowOp, Index);
10241018 }
10251019
10261020 return nullptr ;
@@ -2069,11 +2063,11 @@ static Type *shrinkFPConstantVector(Value *V, bool PreferBFloat) {
20692063
20702064 // For fixed-width vectors we find the minimal type by looking
20712065 // through the constant values of the vector.
2072- for (unsigned i = 0 ; i != NumElts; ++i ) {
2073- if (isa<UndefValue> (CV->getAggregateElement (i )))
2066+ for (unsigned I = 0 ; I != NumElts; ++I ) {
2067+ if (match (CV->getAggregateElement (I), m_Poison ( )))
20742068 continue ;
20752069
2076- auto *CFP = dyn_cast_or_null<ConstantFP>(CV->getAggregateElement (i ));
2070+ auto *CFP = dyn_cast_or_null<ConstantFP>(CV->getAggregateElement (I ));
20772071 if (!CFP)
20782072 return nullptr ;
20792073
@@ -2763,8 +2757,9 @@ static bool collectInsertionElements(Value *V, unsigned Shift,
27632757 assert (isMultipleOfTypeSize (Shift, VecEltTy) &&
27642758 " Shift should be a multiple of the element type size" );
27652759
2766- // Undef values never contribute useful bits to the result.
2767- if (isa<UndefValue>(V)) return true ;
2760+ // Poison values never contribute useful bits to the result.
2761+ if (match (V, m_Poison ()))
2762+ return true ;
27682763
27692764 // If we got down to a value of the right type, we win, try inserting into the
27702765 // right element.
0 commit comments