@@ -135,6 +135,7 @@ static Constant *constantFoldWrRegion(Type *RetTy,
135
135
const CMRegion &R, const DataLayout &DL) {
136
136
Constant *OldValue = Operands[GenXIntrinsic::GenXRegion::OldValueOperandNum];
137
137
Constant *NewValue = Operands[GenXIntrinsic::GenXRegion::NewValueOperandNum];
138
+ Constant *Mask = Operands[GenXIntrinsic::GenXRegion::PredicateOperandNum];
138
139
// The inputs can be ConstantExpr if we are being called from
139
140
// CallAnalyzer.
140
141
if (isa<ConstantExpr>(OldValue) || isa<ConstantExpr>(NewValue))
@@ -147,7 +148,8 @@ static Constant *constantFoldWrRegion(Type *RetTy,
147
148
148
149
const int RetElemSize = DL.getTypeSizeInBits (RetTy->getScalarType ()) / 8 ;
149
150
unsigned Offset = OffsetC->getSExtValue () / RetElemSize;
150
- if (isa<UndefValue>(OldValue) && R.isContiguous () && (Offset == 0 )) {
151
+ if (isa<UndefValue>(OldValue) && R.isContiguous () && Offset == 0 &&
152
+ Mask->isAllOnesValue ()) {
151
153
// If old value is undef and new value is splat, and the result vector
152
154
// is no bigger than 2 GRFs, then just return a splat of the right type.
153
155
Constant *Splat = NewValue;
@@ -172,7 +174,7 @@ static Constant *constantFoldWrRegion(Type *RetTy,
172
174
return UndefValue::get (RetTy); // out of range index
173
175
if (!isa<VectorType>(NewValue->getType ()))
174
176
Values[Offset] = NewValue;
175
- else {
177
+ else if (!Mask-> isZeroValue ()) {
176
178
unsigned RowIdx = Offset;
177
179
unsigned Idx = RowIdx;
178
180
unsigned NextRow = R.Width ;
@@ -185,7 +187,10 @@ static Constant *constantFoldWrRegion(Type *RetTy,
185
187
if (Idx >= WholeNumElements)
186
188
// return collected values even if idx is out of bounds
187
189
return ConstantVector::get (Values);
188
- Values[Idx] = NewValue->getAggregateElement (i);
190
+ if (Mask->isAllOnesValue () ||
191
+ (Mask->getType ()->isVectorTy () &&
192
+ !cast<ConstantVector>(Mask)->getAggregateElement (i)->isZeroValue ()))
193
+ Values[Idx] = NewValue->getAggregateElement (i);
189
194
Idx += R.Stride ;
190
195
}
191
196
}
0 commit comments