llvm.org GIT mirror llvm / a1e0ced
Merging r322473: ------------------------------------------------------------------------ r322473 | a.elovikov | 2018-01-15 02:56:07 -0800 (Mon, 15 Jan 2018) | 23 lines [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 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@322673 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 1 year, 7 months ago
2 changed file(s) with 60 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
26292629 Instruction *LastInduction = VecInd;
26302630 for (unsigned Part = 0; Part < UF; ++Part) {
26312631 VectorLoopValueMap.setVectorValue(EntryVal, Part, LastInduction);
2632 recordVectorLoopValueForInductionCast(II, LastInduction, Part);
2632
26332633 if (isa(EntryVal))
26342634 addMetadata(LastInduction, EntryVal);
2635 else
2636 recordVectorLoopValueForInductionCast(II, LastInduction, Part);
2637
26352638 LastInduction = cast(addFastMathFlag(
26362639 Builder.CreateBinOp(AddOp, LastInduction, SplatVF, "step.add")));
26372640 }
27532756
27542757 // If we haven't yet vectorized the induction variable, splat the scalar
27552758 // induction variable, and build the necessary step vectors.
2759 // TODO: Don't do it unless the vectorized IV is really required.
27562760 if (!VectorizedIV) {
27572761 Value *Broadcasted = getBroadcastInstrs(ScalarIV);
27582762 for (unsigned Part = 0; Part < UF; ++Part) {
27592763 Value *EntryPart =
27602764 getStepVector(Broadcasted, VF * Part, Step, ID.getInductionOpcode());
27612765 VectorLoopValueMap.setVectorValue(EntryVal, Part, EntryPart);
2762 recordVectorLoopValueForInductionCast(ID, EntryPart, Part);
27632766 if (Trunc)
27642767 addMetadata(EntryPart, Trunc);
2768 else
2769 recordVectorLoopValueForInductionCast(ID, EntryPart, Part);
27652770 }
27662771 }
27672772
0 ; RUN: opt -S -loop-vectorize -force-vector-width=4 -force-vector-interleave=1 < %s 2>&1 | FileCheck %s
1 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
2 @a = common local_unnamed_addr global i32 0, align 4
3 @b = common local_unnamed_addr global i8 0, align 1
4
5 ; Function Attrs: norecurse nounwind uwtable
6 define void @doit1() local_unnamed_addr{
7 entry:
8 br label %for.body
9
10 for.body:
11 %main.iv = phi i32 [ 0, %entry ], [ %inc, %for.body ]
12
13 %i8.iv = phi i8 [ 0, %entry ], [ %i8.add, %for.body ]
14 %i32.iv = phi i32 [ 0, %entry ], [ %i32.add, %for.body ]
15
16 %trunc.to.be.converted.to.new.iv = trunc i32 %i32.iv to i8
17 %i8.add = add i8 %i8.iv, %trunc.to.be.converted.to.new.iv
18
19 %noop.conv.under.pse = and i32 %i32.iv, 255
20 %i32.add = add nuw nsw i32 %noop.conv.under.pse, 9
21
22 %inc = add i32 %main.iv, 1
23 %tobool = icmp eq i32 %inc, 16
24 br i1 %tobool, label %for.cond.for.end_crit_edge, label %for.body
25
26 ; CHECK-LABEL: @doit1(
27 ; CHECK: vector.body:
28 ; CHECK-NEXT: [[MAIN_IV:%.*]] = phi i32 [ 0, [[VECTOR_PH:%.*]] ], [ [[MAIN_IV_NEXT:%.*]], [[VECTOR_BODY:%.*]] ]
29 ; CHECK-NEXT: [[I8_IV:%.*]] = phi <4 x i8> [ zeroinitializer, [[VECTOR_PH]] ], [ [[I8_IV_NEXT:%.*]], [[VECTOR_BODY]] ]
30 ; CHECK-NEXT: [[I32_IV:%.*]] = phi <4 x i32> [ , [[VECTOR_PH]] ], [ [[I32_IV_NEXT:%.*]], [[VECTOR_BODY]] ]
31 ; CHECK-NEXT: [[IV_FROM_TRUNC:%.*]] = phi <4 x i8> [ , [[VECTOR_PH]] ], [ [[IV_FROM_TRUNC_NEXT:%.*]], [[VECTOR_BODY]] ]
32
33 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> undef, i32 [[MAIN_IV]], i32 0
34 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> undef, <4 x i32> zeroinitializer
35 ; CHECK-NEXT: [[INDUCTION:%.*]] = add <4 x i32> [[BROADCAST_SPLAT]],
36 ; CHECK-NEXT: [[TMP7:%.*]] = add i32 [[MAIN_IV]], 0
37
38 ; CHECK-NEXT: [[I8_IV_NEXT]] = add <4 x i8> [[I8_IV]], [[IV_FROM_TRUNC]]
39
40 ; CHECK-NEXT: [[MAIN_IV_NEXT]] = add i32 [[MAIN_IV]], 4
41 ; CHECK-NEXT: [[I32_IV_NEXT]] = add <4 x i32> [[I32_IV]],
42 ; CHECK-NEXT: [[IV_FROM_TRUNC_NEXT]] = add <4 x i8> [[IV_FROM_TRUNC]],
43 ; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i32 [[MAIN_IV_NEXT]], 16
44 ; CHECK-NEXT: br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop !0
45
46 for.cond.for.end_crit_edge:
47 store i8 %i8.add, i8* @b, align 1
48 br label %for.end
49
50 for.end:
51 ret void
52 }