[llvm] r322473 - [LV] Don't call recordVectorLoopValueForInductionCast for newly-created IV from a trunc.

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 07:59:12 PST 2018


Merged to 6.0 in r322673.

On Mon, Jan 15, 2018 at 11:56 AM, Andrei Elovikov via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: a.elovikov
> Date: Mon Jan 15 02:56:07 2018
> New Revision: 322473
>
> URL: http://llvm.org/viewvc/llvm-project?rev=322473&view=rev
> Log:
> [LV] Don't call recordVectorLoopValueForInductionCast for newly-created IV from a trunc.
>
> Summary:
> This method is supposed to be called for IVs that have casts in their use-def
> chains that are completely ignored after vectorization under PSE. However, for
> truncates of such IVs the same InductionDescriptor is used during
> creation/widening of both original IV based on PHINode and new IV based on
> TruncInst.
>
> This leads to unintended second call to recordVectorLoopValueForInductionCast
> with a VectorLoopVal set to the newly created IV for a trunc and causes an
> assert due to attempt to store new information for already existing entry in the
> map. This is wrong and should not be done.
>
> Fixes PR35773.
>
> Reviewers: dorit, Ayal, mssimpso
>
> Reviewed By: dorit
>
> Subscribers: RKSimon, dim, dcaballe, hsaito, llvm-commits, hiraditya
>
> Differential Revision: https://reviews.llvm.org/D41913
>
> Added:
>     llvm/trunk/test/Transforms/LoopVectorize/pr35773.ll
> Modified:
>     llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
>
> Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=322473&r1=322472&r2=322473&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
> +++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Mon Jan 15 02:56:07 2018
> @@ -2435,9 +2435,12 @@ void InnerLoopVectorizer::createVectorIn
>    Instruction *LastInduction = VecInd;
>    for (unsigned Part = 0; Part < UF; ++Part) {
>      VectorLoopValueMap.setVectorValue(EntryVal, Part, LastInduction);
> -    recordVectorLoopValueForInductionCast(II, LastInduction, Part);
> +
>      if (isa<TruncInst>(EntryVal))
>        addMetadata(LastInduction, EntryVal);
> +    else
> +      recordVectorLoopValueForInductionCast(II, LastInduction, Part);
> +
>      LastInduction = cast<Instruction>(addFastMathFlag(
>          Builder.CreateBinOp(AddOp, LastInduction, SplatVF, "step.add")));
>    }
> @@ -2559,15 +2562,17 @@ void InnerLoopVectorizer::widenIntOrFpIn
>
>    // If we haven't yet vectorized the induction variable, splat the scalar
>    // induction variable, and build the necessary step vectors.
> +  // TODO: Don't do it unless the vectorized IV is really required.
>    if (!VectorizedIV) {
>      Value *Broadcasted = getBroadcastInstrs(ScalarIV);
>      for (unsigned Part = 0; Part < UF; ++Part) {
>        Value *EntryPart =
>            getStepVector(Broadcasted, VF * Part, Step, ID.getInductionOpcode());
>        VectorLoopValueMap.setVectorValue(EntryVal, Part, EntryPart);
> -      recordVectorLoopValueForInductionCast(ID, EntryPart, Part);
>        if (Trunc)
>          addMetadata(EntryPart, Trunc);
> +      else
> +        recordVectorLoopValueForInductionCast(ID, EntryPart, Part);
>      }
>    }
>
>
> Added: llvm/trunk/test/Transforms/LoopVectorize/pr35773.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopVectorize/pr35773.ll?rev=322473&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/LoopVectorize/pr35773.ll (added)
> +++ llvm/trunk/test/Transforms/LoopVectorize/pr35773.ll Mon Jan 15 02:56:07 2018
> @@ -0,0 +1,53 @@
> +; RUN: opt -S -loop-vectorize -force-vector-width=4 -force-vector-interleave=1 < %s 2>&1 | FileCheck %s
> +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> + at a = common local_unnamed_addr global i32 0, align 4
> + at b = common local_unnamed_addr global i8 0, align 1
> +
> +; Function Attrs: norecurse nounwind uwtable
> +define void @doit1() local_unnamed_addr{
> +entry:
> +  br label %for.body
> +
> +for.body:
> +  %main.iv = phi i32 [ 0, %entry ], [ %inc, %for.body ]
> +
> +  %i8.iv = phi i8 [ 0, %entry ], [ %i8.add, %for.body ]
> +  %i32.iv = phi i32 [ 0, %entry ], [ %i32.add, %for.body ]
> +
> +  %trunc.to.be.converted.to.new.iv = trunc i32 %i32.iv to i8
> +  %i8.add = add i8 %i8.iv, %trunc.to.be.converted.to.new.iv
> +
> +  %noop.conv.under.pse = and i32 %i32.iv, 255
> +  %i32.add = add nuw nsw i32 %noop.conv.under.pse, 9
> +
> +  %inc = add i32 %main.iv, 1
> +  %tobool = icmp eq i32 %inc, 16
> +  br i1 %tobool, label %for.cond.for.end_crit_edge, label %for.body
> +
> +; CHECK-LABEL: @doit1(
> +; CHECK:       vector.body:
> +; CHECK-NEXT:    [[MAIN_IV:%.*]] = phi i32 [ 0, [[VECTOR_PH:%.*]] ], [ [[MAIN_IV_NEXT:%.*]], [[VECTOR_BODY:%.*]] ]
> +; CHECK-NEXT:    [[I8_IV:%.*]] = phi <4 x i8> [ zeroinitializer, [[VECTOR_PH]] ], [ [[I8_IV_NEXT:%.*]], [[VECTOR_BODY]] ]
> +; CHECK-NEXT:    [[I32_IV:%.*]] = phi <4 x i32> [ <i32 0, i32 9, i32 18, i32 27>, [[VECTOR_PH]] ], [ [[I32_IV_NEXT:%.*]], [[VECTOR_BODY]] ]
> +; CHECK-NEXT:    [[IV_FROM_TRUNC:%.*]] = phi <4 x i8> [ <i8 0, i8 9, i8 18, i8 27>, [[VECTOR_PH]] ], [ [[IV_FROM_TRUNC_NEXT:%.*]], [[VECTOR_BODY]] ]
> +
> +; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> undef, i32 [[MAIN_IV]], i32 0
> +; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> undef, <4 x i32> zeroinitializer
> +; CHECK-NEXT:    [[INDUCTION:%.*]] = add <4 x i32> [[BROADCAST_SPLAT]], <i32 0, i32 1, i32 2, i32 3>
> +; CHECK-NEXT:    [[TMP7:%.*]] = add i32 [[MAIN_IV]], 0
> +
> +; CHECK-NEXT:    [[I8_IV_NEXT]] = add <4 x i8> [[I8_IV]], [[IV_FROM_TRUNC]]
> +
> +; CHECK-NEXT:    [[MAIN_IV_NEXT]] = add i32 [[MAIN_IV]], 4
> +; CHECK-NEXT:    [[I32_IV_NEXT]] = add <4 x i32> [[I32_IV]], <i32 36, i32 36, i32 36, i32 36>
> +; CHECK-NEXT:    [[IV_FROM_TRUNC_NEXT]] = add <4 x i8> [[IV_FROM_TRUNC]], <i8 36, i8 36, i8 36, i8 36>
> +; CHECK-NEXT:    [[TMP9:%.*]] = icmp eq i32 [[MAIN_IV_NEXT]], 16
> +; CHECK-NEXT:    br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop !0
> +
> +for.cond.for.end_crit_edge:
> +  store i8 %i8.add, i8* @b, align 1
> +  br label %for.end
> +
> +for.end:
> +  ret void
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list