@@ -253,7 +253,7 @@ bool LoopIdiomVectorize::run(Loop *L) {
253
253
254
254
if (recognizeMinIdxPattern ())
255
255
return true ;
256
-
256
+
257
257
return false ;
258
258
}
259
259
@@ -361,6 +361,14 @@ bool LoopIdiomVectorize::recognizeMinIdxPattern() {
361
361
return false ;
362
362
}
363
363
364
+ // In some cases, the pointer used to load comes from a GEP instruction.
365
+ // In particular, Flang uses offsetted pointer but for vectorized
366
+ // version, we need the base of the GEP.
367
+ if (isa<GetElementPtrInst>(BasePtr)) {
368
+ LLVM_DEBUG (dbgs () << " Extracting BasePtr from GEP\n " );
369
+ BasePtr = cast<GetElementPtrInst>(BasePtr)->getPointerOperand ();
370
+ }
371
+
364
372
// Extract FCmp and validate load types
365
373
auto *FCmp = dyn_cast<FCmpInst>(SelectToInspect->getCondition ());
366
374
if (!FCmp || !isa<LoadInst>(FCmp->getOperand (0 )) ||
@@ -820,17 +828,13 @@ bool LoopIdiomVectorize::transformMinIdxPattern(
820
828
// %minidx.partial.2.if.add) %minidx.partial.2.if.gep = getelementptr inbounds
821
829
// nuw float, ptr %p, i64 %FirstIndex
822
830
Value *MinIdxPartial2IfAdd =
823
- Builder.CreateAdd (MinIdxVectEndLCSSA, ConstantInt::get (I64Ty, 0 ),
831
+ Builder.CreateAdd (MinIdxVectEndLCSSA, ConstantInt::get (I64Ty, 1 ),
824
832
" minidx.partial.2.if.add.zero" );
825
833
Value *MinIdxPartial2IfMask = Builder.CreateCall (
826
834
Intrinsic::getOrInsertDeclaration (M, Intrinsic::get_active_lane_mask,
827
835
{MaskTy, I64Ty}),
828
836
{FirstIndex, MinIdxPartial2IfAdd}, " minidx.partial.2.if.mask" );
829
837
830
- // Reverse the mask.
831
- MinIdxPartial2IfMask = Builder.CreateCall (
832
- Intrinsic::getOrInsertDeclaration (M, Intrinsic::vector_reverse, {MaskTy}),
833
- {MinIdxPartial2IfMask}, " minidx.partial.2.if.mask.reverse" );
834
838
835
839
Value *FirstIndexMinus1 =
836
840
Builder.CreateSub (FirstIndex, ConstantInt::get (I64Ty, 1 ),
@@ -852,9 +856,16 @@ bool LoopIdiomVectorize::transformMinIdxPattern(
852
856
{MinIdxPartial2IfGEP, ConstantInt::get (I32Ty, 1 ),
853
857
MinIdxPartial2IfMask, Constant::getNullValue (VecTy)},
854
858
" minidx.partial.2.if.load" );
859
+ Value *MinIdxPartial2IfSelectVals =
860
+ Builder.CreateSelect (MinIdxPartial2IfMask, MinIdxPartial2IfLoad, GMax, " minidx.partial2.if.finalVals" );
861
+
862
+ // Reverse the mask.
863
+ MinIdxPartial2IfMask = Builder.CreateCall (
864
+ Intrinsic::getOrInsertDeclaration (M, Intrinsic::vector_reverse, {MaskTy}),
865
+ {MinIdxPartial2IfMask}, " minidx.partial.2.if.mask.reverse" );
855
866
Value *MinIdxPartial2IfReverse = Builder.CreateCall (
856
867
Intrinsic::getOrInsertDeclaration (M, Intrinsic::vector_reverse, {VecTy}),
857
- {MinIdxPartial2IfLoad }, " minidx.partial.2.if.reverse" );
868
+ {MinIdxPartial2IfSelectVals }, " minidx.partial.2.if.reverse" );
858
869
Value *MinIdxPartial2IfReduce = Builder.CreateCall (
859
870
Intrinsic::getOrInsertDeclaration (M, Intrinsic::vector_reduce_fminimum,
860
871
{VecTy}),
0 commit comments