@@ -38,6 +38,7 @@ static bool isIntrinsicExpansion(Function &F) {
38
38
case Intrinsic::log:
39
39
case Intrinsic::log10:
40
40
case Intrinsic::pow:
41
+ case Intrinsic::dx_all:
41
42
case Intrinsic::dx_any:
42
43
case Intrinsic::dx_clamp:
43
44
case Intrinsic::dx_uclamp:
@@ -54,8 +55,7 @@ static bool isIntrinsicExpansion(Function &F) {
54
55
55
56
static Value *expandAbs (CallInst *Orig) {
56
57
Value *X = Orig->getOperand (0 );
57
- IRBuilder<> Builder (Orig->getParent ());
58
- Builder.SetInsertPoint (Orig);
58
+ IRBuilder<> Builder (Orig);
59
59
Type *Ty = X->getType ();
60
60
Type *EltTy = Ty->getScalarType ();
61
61
Constant *Zero = Ty->isVectorTy ()
@@ -148,8 +148,7 @@ static Value *expandIntegerDotIntrinsic(CallInst *Orig,
148
148
149
149
static Value *expandExpIntrinsic (CallInst *Orig) {
150
150
Value *X = Orig->getOperand (0 );
151
- IRBuilder<> Builder (Orig->getParent ());
152
- Builder.SetInsertPoint (Orig);
151
+ IRBuilder<> Builder (Orig);
153
152
Type *Ty = X->getType ();
154
153
Type *EltTy = Ty->getScalarType ();
155
154
Constant *Log2eConst =
@@ -166,13 +165,21 @@ static Value *expandExpIntrinsic(CallInst *Orig) {
166
165
return Exp2Call;
167
166
}
168
167
169
- static Value *expandAnyIntrinsic (CallInst *Orig) {
168
+ static Value *expandAnyOrAllIntrinsic (CallInst *Orig,
169
+ Intrinsic::ID intrinsicId) {
170
170
Value *X = Orig->getOperand (0 );
171
- IRBuilder<> Builder (Orig->getParent ());
172
- Builder.SetInsertPoint (Orig);
171
+ IRBuilder<> Builder (Orig);
173
172
Type *Ty = X->getType ();
174
173
Type *EltTy = Ty->getScalarType ();
175
174
175
+ auto ApplyOp = [&Builder](Intrinsic::ID IntrinsicId, Value *Result,
176
+ Value *Elt) {
177
+ if (IntrinsicId == Intrinsic::dx_any)
178
+ return Builder.CreateOr (Result, Elt);
179
+ assert (IntrinsicId == Intrinsic::dx_all);
180
+ return Builder.CreateAnd (Result, Elt);
181
+ };
182
+
176
183
Value *Result = nullptr ;
177
184
if (!Ty->isVectorTy ()) {
178
185
Result = EltTy->isFloatingPointTy ()
@@ -193,16 +200,15 @@ static Value *expandAnyIntrinsic(CallInst *Orig) {
193
200
Result = Builder.CreateExtractElement (Cond, (uint64_t )0 );
194
201
for (unsigned I = 1 ; I < XVec->getNumElements (); I++) {
195
202
Value *Elt = Builder.CreateExtractElement (Cond, I);
196
- Result = Builder. CreateOr ( Result, Elt);
203
+ Result = ApplyOp (intrinsicId, Result, Elt);
197
204
}
198
205
}
199
206
return Result;
200
207
}
201
208
202
209
static Value *expandLengthIntrinsic (CallInst *Orig) {
203
210
Value *X = Orig->getOperand (0 );
204
- IRBuilder<> Builder (Orig->getParent ());
205
- Builder.SetInsertPoint (Orig);
211
+ IRBuilder<> Builder (Orig);
206
212
Type *Ty = X->getType ();
207
213
Type *EltTy = Ty->getScalarType ();
208
214
@@ -230,8 +236,7 @@ static Value *expandLerpIntrinsic(CallInst *Orig) {
230
236
Value *X = Orig->getOperand (0 );
231
237
Value *Y = Orig->getOperand (1 );
232
238
Value *S = Orig->getOperand (2 );
233
- IRBuilder<> Builder (Orig->getParent ());
234
- Builder.SetInsertPoint (Orig);
239
+ IRBuilder<> Builder (Orig);
235
240
auto *V = Builder.CreateFSub (Y, X);
236
241
V = Builder.CreateFMul (S, V);
237
242
return Builder.CreateFAdd (X, V, " dx.lerp" );
@@ -240,8 +245,7 @@ static Value *expandLerpIntrinsic(CallInst *Orig) {
240
245
static Value *expandLogIntrinsic (CallInst *Orig,
241
246
float LogConstVal = numbers::ln2f) {
242
247
Value *X = Orig->getOperand (0 );
243
- IRBuilder<> Builder (Orig->getParent ());
244
- Builder.SetInsertPoint (Orig);
248
+ IRBuilder<> Builder (Orig);
245
249
Type *Ty = X->getType ();
246
250
Type *EltTy = Ty->getScalarType ();
247
251
Constant *Ln2Const =
@@ -266,8 +270,7 @@ static Value *expandNormalizeIntrinsic(CallInst *Orig) {
266
270
Value *X = Orig->getOperand (0 );
267
271
Type *Ty = Orig->getType ();
268
272
Type *EltTy = Ty->getScalarType ();
269
- IRBuilder<> Builder (Orig->getParent ());
270
- Builder.SetInsertPoint (Orig);
273
+ IRBuilder<> Builder (Orig);
271
274
272
275
auto *XVec = dyn_cast<FixedVectorType>(Ty);
273
276
if (!XVec) {
@@ -305,8 +308,7 @@ static Value *expandPowIntrinsic(CallInst *Orig) {
305
308
Value *X = Orig->getOperand (0 );
306
309
Value *Y = Orig->getOperand (1 );
307
310
Type *Ty = X->getType ();
308
- IRBuilder<> Builder (Orig->getParent ());
309
- Builder.SetInsertPoint (Orig);
311
+ IRBuilder<> Builder (Orig);
310
312
311
313
auto *Log2Call =
312
314
Builder.CreateIntrinsic (Ty, Intrinsic::log2, {X}, nullptr , " elt.log2" );
@@ -350,8 +352,7 @@ static Value *expandClampIntrinsic(CallInst *Orig,
350
352
Value *Min = Orig->getOperand (1 );
351
353
Value *Max = Orig->getOperand (2 );
352
354
Type *Ty = X->getType ();
353
- IRBuilder<> Builder (Orig->getParent ());
354
- Builder.SetInsertPoint (Orig);
355
+ IRBuilder<> Builder (Orig);
355
356
auto *MaxCall = Builder.CreateIntrinsic (
356
357
Ty, getMaxForClamp (Ty, ClampIntrinsic), {X, Min}, nullptr , " dx.max" );
357
358
return Builder.CreateIntrinsic (Ty, getMinForClamp (Ty, ClampIntrinsic),
@@ -360,7 +361,8 @@ static Value *expandClampIntrinsic(CallInst *Orig,
360
361
361
362
static bool expandIntrinsic (Function &F, CallInst *Orig) {
362
363
Value *Result = nullptr ;
363
- switch (F.getIntrinsicID ()) {
364
+ Intrinsic::ID IntrinsicId = F.getIntrinsicID ();
365
+ switch (IntrinsicId) {
364
366
case Intrinsic::abs:
365
367
Result = expandAbs (Orig);
366
368
break ;
@@ -376,12 +378,13 @@ static bool expandIntrinsic(Function &F, CallInst *Orig) {
376
378
case Intrinsic::pow:
377
379
Result = expandPowIntrinsic (Orig);
378
380
break ;
381
+ case Intrinsic::dx_all:
379
382
case Intrinsic::dx_any:
380
- Result = expandAnyIntrinsic (Orig);
383
+ Result = expandAnyOrAllIntrinsic (Orig, IntrinsicId );
381
384
break ;
382
385
case Intrinsic::dx_uclamp:
383
386
case Intrinsic::dx_clamp:
384
- Result = expandClampIntrinsic (Orig, F. getIntrinsicID () );
387
+ Result = expandClampIntrinsic (Orig, IntrinsicId );
385
388
break ;
386
389
case Intrinsic::dx_lerp:
387
390
Result = expandLerpIntrinsic (Orig);
@@ -397,7 +400,7 @@ static bool expandIntrinsic(Function &F, CallInst *Orig) {
397
400
break ;
398
401
case Intrinsic::dx_sdot:
399
402
case Intrinsic::dx_udot:
400
- Result = expandIntegerDotIntrinsic (Orig, F. getIntrinsicID () );
403
+ Result = expandIntegerDotIntrinsic (Orig, IntrinsicId );
401
404
break ;
402
405
}
403
406
0 commit comments