2020-05-13 03:23:09 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2019-04-17 12:52:47 +08:00
|
|
|
; RUN: opt -loop-vectorize -force-vector-width=4 -S < %s | FileCheck %s
|
|
|
|
|
|
|
|
; This is the test case from PR26314.
|
|
|
|
; When we were retrying dependence checking with memchecks only,
|
|
|
|
; the loop-invariant access in the inner loop was incorrectly determined to be wrapping
|
|
|
|
; because it was not strided in the inner loop.
|
|
|
|
; Improved wrapping detection allows vectorization in the following case.
|
|
|
|
|
|
|
|
; #define Z 32
|
|
|
|
; typedef struct s {
|
|
|
|
; int v1[Z];
|
|
|
|
; int v2[Z];
|
|
|
|
; int v3[Z][Z];
|
|
|
|
; } s;
|
|
|
|
;
|
|
|
|
; void slow_function (s* const obj, int z) {
|
|
|
|
; for (int j=0; j<Z; j++) {
|
|
|
|
; for (int k=0; k<z; k++) {
|
|
|
|
; int x = obj->v1[k] + obj->v2[j];
|
|
|
|
; obj->v3[j][k] += x;
|
|
|
|
; }
|
|
|
|
; }
|
|
|
|
; }
|
|
|
|
|
|
|
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
|
|
|
|
|
|
|
%struct.s = type { [32 x i32], [32 x i32], [32 x [32 x i32]] }
|
|
|
|
|
|
|
|
define void @Test(%struct.s* nocapture %obj, i64 %z) #0 {
|
2020-05-13 03:23:09 +08:00
|
|
|
; CHECK-LABEL: @Test(
|
|
|
|
; CHECK-NEXT: [[OBJ4:%.*]] = bitcast %struct.s* [[OBJ:%.*]] to i8*
|
|
|
|
; CHECK-NEXT: [[SCEVGEP5:%.*]] = getelementptr [[STRUCT_S:%.*]], %struct.s* [[OBJ]], i64 0, i32 0, i64 [[Z:%.*]]
|
|
|
|
; CHECK-NEXT: [[SCEVGEP56:%.*]] = bitcast i32* [[SCEVGEP5]] to i8*
|
|
|
|
; CHECK-NEXT: br label [[DOTOUTER_PREHEADER:%.*]]
|
|
|
|
; CHECK: .outer.preheader:
|
|
|
|
; CHECK-NEXT: [[I:%.*]] = phi i64 [ 0, [[TMP0:%.*]] ], [ [[I_NEXT:%.*]], [[DOTOUTER:%.*]] ]
|
|
|
|
; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr [[STRUCT_S]], %struct.s* [[OBJ]], i64 0, i32 2, i64 [[I]], i64 0
|
|
|
|
; CHECK-NEXT: [[SCEVGEP1:%.*]] = bitcast i32* [[SCEVGEP]] to i8*
|
|
|
|
; CHECK-NEXT: [[SCEVGEP2:%.*]] = getelementptr [[STRUCT_S]], %struct.s* [[OBJ]], i64 0, i32 2, i64 [[I]], i64 [[Z]]
|
|
|
|
; CHECK-NEXT: [[SCEVGEP23:%.*]] = bitcast i32* [[SCEVGEP2]] to i8*
|
|
|
|
; CHECK-NEXT: [[SCEVGEP7:%.*]] = getelementptr [[STRUCT_S]], %struct.s* [[OBJ]], i64 0, i32 1, i64 [[I]]
|
|
|
|
; CHECK-NEXT: [[SCEVGEP78:%.*]] = bitcast i32* [[SCEVGEP7]] to i8*
|
|
|
|
; CHECK-NEXT: [[UGLYGEP:%.*]] = getelementptr i8, i8* [[SCEVGEP78]], i64 1
|
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_S]], %struct.s* [[OBJ]], i64 0, i32 1, i64 [[I]]
|
|
|
|
; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[Z]], 4
|
|
|
|
; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
|
|
|
|
; CHECK: vector.memcheck:
|
|
|
|
; CHECK-NEXT: [[BOUND0:%.*]] = icmp ult i8* [[SCEVGEP1]], [[SCEVGEP56]]
|
|
|
|
; CHECK-NEXT: [[BOUND1:%.*]] = icmp ult i8* [[OBJ4]], [[SCEVGEP23]]
|
|
|
|
; CHECK-NEXT: [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
|
|
|
|
; CHECK-NEXT: [[BC:%.*]] = bitcast i32* [[TMP1]] to i8*
|
|
|
|
; CHECK-NEXT: [[BOUND09:%.*]] = icmp ult i8* [[SCEVGEP1]], [[UGLYGEP]]
|
|
|
|
; CHECK-NEXT: [[BOUND110:%.*]] = icmp ult i8* [[BC]], [[SCEVGEP23]]
|
|
|
|
; CHECK-NEXT: [[FOUND_CONFLICT11:%.*]] = and i1 [[BOUND09]], [[BOUND110]]
|
|
|
|
; CHECK-NEXT: [[CONFLICT_RDX:%.*]] = or i1 [[FOUND_CONFLICT]], [[FOUND_CONFLICT11]]
|
|
|
|
; CHECK-NEXT: [[MEMCHECK_CONFLICT:%.*]] = and i1 [[CONFLICT_RDX]], true
|
|
|
|
; CHECK-NEXT: br i1 [[MEMCHECK_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
|
|
|
|
; CHECK: vector.ph:
|
|
|
|
; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[Z]], 4
|
|
|
|
; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[Z]], [[N_MOD_VF]]
|
|
|
|
; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
|
|
|
|
; CHECK: vector.body:
|
|
|
|
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[INDEX]], 0
|
|
|
|
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [[STRUCT_S]], %struct.s* [[OBJ]], i64 0, i32 0, i64 [[TMP2]]
|
|
|
|
; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[TMP3]], i32 0
|
|
|
|
; CHECK-NEXT: [[TMP5:%.*]] = bitcast i32* [[TMP4]] to <4 x i32>*
|
|
|
|
; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, <4 x i32>* [[TMP5]], align 4, !alias.scope !0
|
Infer alignment of unmarked loads in IR/bitcode parsing.
For IR generated by a compiler, this is really simple: you just take the
datalayout from the beginning of the file, and apply it to all the IR
later in the file. For optimization testcases that don't care about the
datalayout, this is also really simple: we just use the default
datalayout.
The complexity here comes from the fact that some LLVM tools allow
overriding the datalayout: some tools have an explicit flag for this,
some tools will infer a datalayout based on the code generation target.
Supporting this properly required plumbing through a bunch of new
machinery: we want to allow overriding the datalayout after the
datalayout is parsed from the file, but before we use any information
from it. Therefore, IR/bitcode parsing now has a callback to allow tools
to compute the datalayout at the appropriate time.
Not sure if I covered all the LLVM tools that want to use the callback.
(clang? lli? Misc IR manipulation tools like llvm-link?). But this is at
least enough for all the LLVM regression tests, and IR without a
datalayout is not something frontends should generate.
This change had some sort of weird effects for certain CodeGen
regression tests: if the datalayout is overridden with a datalayout with
a different program or stack address space, we now parse IR based on the
overridden datalayout, instead of the one written in the file (or the
default one, if none is specified). This broke a few AVR tests, and one
AMDGPU test.
Outside the CodeGen tests I mentioned, the test changes are all just
fixing CHECK lines and moving around datalayout lines in weird places.
Differential Revision: https://reviews.llvm.org/D78403
2020-05-15 03:59:45 +08:00
|
|
|
; CHECK-NEXT: [[TMP6:%.*]] = load i32, i32* [[TMP1]], align 4, !alias.scope !3
|
2020-11-24 07:23:46 +08:00
|
|
|
; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> undef, i32 [[TMP6]], i32 0
|
|
|
|
; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> undef, <4 x i32> zeroinitializer
|
|
|
|
; CHECK-NEXT: [[TMP7:%.*]] = add nsw <4 x i32> [[BROADCAST_SPLAT]], [[WIDE_LOAD]]
|
|
|
|
; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds [[STRUCT_S]], %struct.s* [[OBJ]], i64 0, i32 2, i64 [[I]], i64 [[TMP2]]
|
|
|
|
; CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds i32, i32* [[TMP8]], i32 0
|
|
|
|
; CHECK-NEXT: [[TMP10:%.*]] = bitcast i32* [[TMP9]] to <4 x i32>*
|
|
|
|
; CHECK-NEXT: [[WIDE_LOAD12:%.*]] = load <4 x i32>, <4 x i32>* [[TMP10]], align 4, !alias.scope !5, !noalias !7
|
|
|
|
; CHECK-NEXT: [[TMP11:%.*]] = add nsw <4 x i32> [[TMP7]], [[WIDE_LOAD12]]
|
|
|
|
; CHECK-NEXT: [[TMP12:%.*]] = bitcast i32* [[TMP9]] to <4 x i32>*
|
|
|
|
; CHECK-NEXT: store <4 x i32> [[TMP11]], <4 x i32>* [[TMP12]], align 4, !alias.scope !5, !noalias !7
|
2020-05-13 03:23:09 +08:00
|
|
|
; CHECK-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 4
|
2020-11-24 07:23:46 +08:00
|
|
|
; CHECK-NEXT: [[TMP13:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
|
|
|
|
; CHECK-NEXT: br i1 [[TMP13]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], [[LOOP8:!llvm.loop !.*]]
|
2020-05-13 03:23:09 +08:00
|
|
|
; CHECK: middle.block:
|
|
|
|
; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[Z]], [[N_VEC]]
|
|
|
|
; CHECK-NEXT: br i1 [[CMP_N]], label [[DOTOUTER]], label [[SCALAR_PH]]
|
|
|
|
; CHECK: scalar.ph:
|
|
|
|
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[DOTOUTER_PREHEADER]] ], [ 0, [[VECTOR_MEMCHECK]] ]
|
|
|
|
; CHECK-NEXT: br label [[DOTINNER:%.*]]
|
|
|
|
; CHECK: .exit:
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
; CHECK: .outer:
|
|
|
|
; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i64 [[I]], 1
|
|
|
|
; CHECK-NEXT: [[EXITCOND_OUTER:%.*]] = icmp eq i64 [[I_NEXT]], 32
|
|
|
|
; CHECK-NEXT: br i1 [[EXITCOND_OUTER]], label [[DOTEXIT:%.*]], label [[DOTOUTER_PREHEADER]]
|
|
|
|
; CHECK: .inner:
|
|
|
|
; CHECK-NEXT: [[J:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[J_NEXT:%.*]], [[DOTINNER]] ]
|
2020-11-24 07:23:46 +08:00
|
|
|
; CHECK-NEXT: [[TMP14:%.*]] = getelementptr inbounds [[STRUCT_S]], %struct.s* [[OBJ]], i64 0, i32 0, i64 [[J]]
|
|
|
|
; CHECK-NEXT: [[TMP15:%.*]] = load i32, i32* [[TMP14]], align 4
|
|
|
|
; CHECK-NEXT: [[TMP16:%.*]] = load i32, i32* [[TMP1]], align 4
|
|
|
|
; CHECK-NEXT: [[TMP17:%.*]] = add nsw i32 [[TMP16]], [[TMP15]]
|
|
|
|
; CHECK-NEXT: [[TMP18:%.*]] = getelementptr inbounds [[STRUCT_S]], %struct.s* [[OBJ]], i64 0, i32 2, i64 [[I]], i64 [[J]]
|
|
|
|
; CHECK-NEXT: [[TMP19:%.*]] = load i32, i32* [[TMP18]], align 4
|
|
|
|
; CHECK-NEXT: [[TMP20:%.*]] = add nsw i32 [[TMP17]], [[TMP19]]
|
|
|
|
; CHECK-NEXT: store i32 [[TMP20]], i32* [[TMP18]], align 4
|
2020-05-13 03:23:09 +08:00
|
|
|
; CHECK-NEXT: [[J_NEXT]] = add nuw nsw i64 [[J]], 1
|
|
|
|
; CHECK-NEXT: [[EXITCOND_INNER:%.*]] = icmp eq i64 [[J_NEXT]], [[Z]]
|
2020-11-24 07:23:46 +08:00
|
|
|
; CHECK-NEXT: br i1 [[EXITCOND_INNER]], label [[DOTOUTER]], label [[DOTINNER]], [[LOOP10:!llvm.loop !.*]]
|
2020-05-13 03:23:09 +08:00
|
|
|
;
|
2019-04-17 12:52:47 +08:00
|
|
|
br label %.outer.preheader
|
|
|
|
|
|
|
|
|
|
|
|
.outer.preheader:
|
|
|
|
%i = phi i64 [ 0, %0 ], [ %i.next, %.outer ]
|
|
|
|
%1 = getelementptr inbounds %struct.s, %struct.s* %obj, i64 0, i32 1, i64 %i
|
|
|
|
br label %.inner
|
|
|
|
|
|
|
|
.exit:
|
|
|
|
ret void
|
2020-05-13 03:23:09 +08:00
|
|
|
|
2019-04-17 12:52:47 +08:00
|
|
|
.outer:
|
|
|
|
%i.next = add nuw nsw i64 %i, 1
|
|
|
|
%exitcond.outer = icmp eq i64 %i.next, 32
|
|
|
|
br i1 %exitcond.outer, label %.exit, label %.outer.preheader
|
|
|
|
|
|
|
|
.inner:
|
|
|
|
%j = phi i64 [ 0, %.outer.preheader ], [ %j.next, %.inner ]
|
|
|
|
%2 = getelementptr inbounds %struct.s, %struct.s* %obj, i64 0, i32 0, i64 %j
|
|
|
|
%3 = load i32, i32* %2
|
|
|
|
%4 = load i32, i32* %1
|
|
|
|
%5 = add nsw i32 %4, %3
|
|
|
|
%6 = getelementptr inbounds %struct.s, %struct.s* %obj, i64 0, i32 2, i64 %i, i64 %j
|
|
|
|
%7 = load i32, i32* %6
|
|
|
|
%8 = add nsw i32 %5, %7
|
2020-05-13 03:23:09 +08:00
|
|
|
store i32 %8, i32* %6
|
2019-04-17 12:52:47 +08:00
|
|
|
%j.next = add nuw nsw i64 %j, 1
|
|
|
|
%exitcond.inner = icmp eq i64 %j.next, %z
|
|
|
|
br i1 %exitcond.inner, label %.outer, label %.inner
|
|
|
|
}
|