Imported Upstream version 5.18.0.205

Former-commit-id: 7f59f7e792705db773f1caecdaa823092f4e2927
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-11-16 08:20:38 +00:00
parent 5cd5df71cc
commit 8e12397d70
28486 changed files with 3867013 additions and 66 deletions

View File

@@ -0,0 +1,36 @@
; Check for recognizing the "memmove" idiom.
; RUN: opt -basicaa -hexagon-loop-idiom -S -mtriple hexagon-unknown-elf < %s \
; RUN: | FileCheck %s
; CHECK: call void @llvm.memmove
; Function Attrs: norecurse nounwind
define void @foo(i32* nocapture %A, i32* nocapture readonly %B, i32 %n) #0 {
entry:
%cmp1 = icmp sgt i32 %n, 0
br i1 %cmp1, label %for.body.preheader, label %for.end
for.body.preheader: ; preds = %entry
%arrayidx.gep = getelementptr i32, i32* %B, i32 0
%arrayidx1.gep = getelementptr i32, i32* %A, i32 0
br label %for.body
for.body: ; preds = %for.body.preheader, %for.body
%arrayidx.phi = phi i32* [ %arrayidx.gep, %for.body.preheader ], [ %arrayidx.inc, %for.body ]
%arrayidx1.phi = phi i32* [ %arrayidx1.gep, %for.body.preheader ], [ %arrayidx1.inc, %for.body ]
%i.02 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
%0 = load i32, i32* %arrayidx.phi, align 4
store i32 %0, i32* %arrayidx1.phi, align 4
%inc = add nuw nsw i32 %i.02, 1
%exitcond = icmp ne i32 %inc, %n
%arrayidx.inc = getelementptr i32, i32* %arrayidx.phi, i32 1
%arrayidx1.inc = getelementptr i32, i32* %arrayidx1.phi, i32 1
br i1 %exitcond, label %for.body, label %for.end.loopexit
for.end.loopexit: ; preds = %for.body
br label %for.end
for.end: ; preds = %for.end.loopexit, %entry
ret void
}
attributes #0 = { nounwind }

View File

@@ -0,0 +1,36 @@
; RUN: opt -basicaa -hexagon-loop-idiom -S -mtriple hexagon-unknown-elf < %s \
; RUN: | FileCheck %s
define void @PR14241(i32* %s, i64 %size) #0 {
; Ensure that we don't form a memcpy for strided loops. Briefly, when we taught
; LoopIdiom about memmove and strided loops, this got miscompiled into a memcpy
; instead of a memmove. If we get the memmove transform back, this will catch
; regressions.
;
; CHECK-LABEL: @PR14241(
entry:
%end.idx = add i64 %size, -1
%end.ptr = getelementptr inbounds i32, i32* %s, i64 %end.idx
br label %while.body
; CHECK-NOT: memcpy
; CHECK: memmove
while.body:
%phi.ptr = phi i32* [ %s, %entry ], [ %next.ptr, %while.body ]
%src.ptr = getelementptr inbounds i32, i32* %phi.ptr, i64 1
%val = load i32, i32* %src.ptr, align 4
; CHECK: load
%dst.ptr = getelementptr inbounds i32, i32* %phi.ptr, i64 0
store i32 %val, i32* %dst.ptr, align 4
; CHECK: store
%next.ptr = getelementptr inbounds i32, i32* %phi.ptr, i64 1
%cmp = icmp eq i32* %next.ptr, %end.ptr
br i1 %cmp, label %exit, label %while.body
exit:
ret void
; CHECK: ret void
}
attributes #0 = { nounwind }

View File

@@ -0,0 +1,46 @@
; RUN: opt -hexagon-loop-idiom -loop-deletion -gvn -S < %s
; REQUIRES: asserts
; This tests that the HexagonLoopIdiom pass does not mark LCSSA information
; as preserved. The pass calls SimplifyInstruction is a couple of places,
; which can invalidate LCSSA. Specifically, the uses of a LCSSA phi variable
; are replaced by the incoming value.
define hidden void @test() local_unnamed_addr #0 {
entry:
br label %if.then63
if.then63:
br i1 undef, label %do.body311, label %if.end375
do.body311:
br i1 undef, label %do.end318, label %do.body311
do.end318:
br i1 undef, label %if.end322, label %if.end375
if.end322:
%sub325 = sub i32 undef, undef
br i1 undef, label %do.end329, label %do.body311
do.end329:
%sub325.lcssa = phi i32 [ %sub325, %if.end322 ]
br label %do.body330
do.body330:
%row_width.7 = phi i32 [ %sub325.lcssa, %do.end329 ], [ %dec334, %do.body330 ]
%sp.5 = phi i8* [ undef, %do.end329 ], [ %incdec.ptr331, %do.body330 ]
%dp.addr.5 = phi i8* [ undef, %do.end329 ], [ %incdec.ptr332, %do.body330 ]
%0 = load i8, i8* %sp.5, align 1
store i8 %0, i8* %dp.addr.5, align 1
%incdec.ptr332 = getelementptr inbounds i8, i8* %dp.addr.5, i32 1
%incdec.ptr331 = getelementptr inbounds i8, i8* %sp.5, i32 1
%dec334 = add i32 %row_width.7, -1
%cmp335 = icmp eq i32 %dec334, 0
br i1 %cmp335, label %if.end375, label %do.body330
if.end375:
ret void
}
attributes #0 = { nounwind }

View File

@@ -0,0 +1,45 @@
; RUN: opt -hexagon-loop-idiom -S < %s | FileCheck %s
; Make sure that we generate correct runtime checks.
; CHECK: b7.old:
; CHECK: [[LEN:%[0-9]+]] = shl i32 %len, 3
; CHECK: [[SRC:%[0-9]+]] = ptrtoint i8* %src to i32
; CHECK: [[DST:%[0-9]+]] = ptrtoint i8* %dst to i32
; CHECK: [[ULT:%[0-9]+]] = icmp ult i32 [[DST]], [[SRC]]
; CHECK: [[SUB:%[0-9]+]] = sub i32 [[DST]], [[SRC]]
; CHECK: [[SLT:%[0-9]+]] = icmp sle i32 [[LEN]], [[SUB]]
; CHECK: [[CND:%[0-9]+]] = or i1 [[ULT]], [[SLT]]
; CHECK: br i1 [[CND]], label %b8.rtli, label %b8.rtli.ph
target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048"
target triple = "hexagon"
define void @fred(i8* %dst, i8* %src, i32 %len) #0 {
b3:
%v4 = bitcast i8* %src to i64*
%v5 = bitcast i8* %dst to i64*
%v6 = icmp slt i32 0, %len
br i1 %v6, label %b7, label %b16
b7: ; preds = %b3
br label %b8
b8: ; preds = %b13, %b7
%v9 = phi i32 [ 0, %b7 ], [ %v14, %b13 ]
%v10 = getelementptr inbounds i64, i64* %v4, i32 %v9
%v11 = load i64, i64* %v10, align 8
%v12 = getelementptr inbounds i64, i64* %v5, i32 %v9
store i64 %v11, i64* %v12, align 8
br label %b13
b13: ; preds = %b8
%v14 = add nsw i32 %v9, 1
%v15 = icmp slt i32 %v14, %len
br i1 %v15, label %b8, label %b16
b16: ; preds = %b13, %b3
ret void
}
attributes #0 = { noinline nounwind "target-cpu"="hexagonv60" }

View File

@@ -0,0 +1,24 @@
; RUN: opt -basicaa -hexagon-loop-idiom -mtriple hexagon-unknown-elf < %s
; REQUIRES: asserts
target triple = "hexagon"
; Function Attrs: nounwind
define void @fred(i8 zeroext %L) #0 {
entry:
br i1 undef, label %if.end53, label %while.body37
while.body37: ; preds = %while.body37, %entry
%i.121 = phi i32 [ %inc46, %while.body37 ], [ 0, %entry ]
%shl = shl i32 1, %i.121
%and39 = and i32 %shl, undef
%tobool40 = icmp eq i32 %and39, 0
%inc46 = add nuw nsw i32 %i.121, 1
%storemerge = select i1 %tobool40, i8 %L, i8 0
br i1 undef, label %while.body37, label %if.end53
if.end53: ; preds = %while.body37, %entry
ret void
}
attributes #0 = { nounwind }

View File

@@ -0,0 +1,83 @@
; RUN: opt -march=hexagon -hexagon-loop-idiom -S < %s | FileCheck %s
; CHECK-LABEL: define void @fred
; Check that this test does not crash.
target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048"
target triple = "hexagon"
%struct.0 = type { [120 x i16], [80 x i16], [80 x i16], [80 x i16], [80 x i16], [80 x i16], [40 x i16], [40 x i16], [40 x i16], [40 x i16], [40 x i16], [40 x i16] }
define void @fred(%struct.0* %demod_state) local_unnamed_addr #0 {
entry:
br label %for.body309
for.body309: ; preds = %for.body309, %entry
%max_diff.0300 = phi i16 [ %max_diff.1, %for.body309 ], [ 0, %entry ]
%arrayidx322.phi = phi i16* [ undef, %entry ], [ %arrayidx322.inc, %for.body309 ]
%arrayidx331.phi = phi i16* [ undef, %entry ], [ %arrayidx331.inc, %for.body309 ]
%lag.4299.apmt = phi i32 [ %inc376.apmt, %for.body309 ], [ 0, %entry ]
%0 = load i16, i16* %arrayidx322.phi, align 2
%conv323 = sext i16 %0 to i32
%sub324 = sub nsw i32 0, %conv323
%ispos258 = icmp sgt i32 %sub324, -1
%1 = select i1 %ispos258, i32 %sub324, i32 0
%add326 = add nsw i32 %1, 0
%2 = load i16, i16* %arrayidx331.phi, align 2
%conv332 = sext i16 %2 to i32
%sub333 = sub nsw i32 0, %conv332
%ispos260 = icmp sgt i32 %sub333, -1
%3 = select i1 %ispos260, i32 %sub333, i32 undef
%sub342 = sub nsw i32 0, %conv323
%ispos262 = icmp sgt i32 %sub342, -1
%4 = select i1 %ispos262, i32 %sub342, i32 undef
%sub351 = sub nsw i32 0, %conv332
%ispos264 = icmp sgt i32 %sub351, -1
%5 = select i1 %ispos264, i32 %sub351, i32 0
%sub360 = sub nsw i32 %conv323, %conv332
%ispos266 = icmp sgt i32 %sub360, -1
%6 = select i1 %ispos266, i32 %sub360, i32 0
%add335 = add nsw i32 %add326, %4
%add344 = add nsw i32 %add335, %3
%add353 = add i32 %add344, %5
%add362 = add i32 %add353, %6
%div363 = sdiv i32 %add362, 6
%conv364 = trunc i32 %div363 to i16
%sext268 = shl i32 %div363, 16
%conv369 = ashr exact i32 %sext268, 16
%conv370 = sext i16 %max_diff.0300 to i32
%cmp371 = icmp sgt i32 %conv369, %conv370
%max_diff.1 = select i1 %cmp371, i16 %conv364, i16 %max_diff.0300
%inc376.apmt = add nuw nsw i32 %lag.4299.apmt, 1
%exitcond331 = icmp ne i32 %inc376.apmt, 40
%arrayidx322.inc = getelementptr i16, i16* %arrayidx322.phi, i32 1
%arrayidx331.inc = getelementptr i16, i16* %arrayidx331.phi, i32 1
br i1 %exitcond331, label %for.body309, label %for.end377
for.end377: ; preds = %for.body309
%max_diff.1.lcssa = phi i16 [ %max_diff.1, %for.body309 ]
%cmp407 = icmp sgt i16 %max_diff.1.lcssa, 4
br label %for.body405
for.body405: ; preds = %if.end437, %for.end377
%arrayidx412 = getelementptr inbounds %struct.0, %struct.0* %demod_state, i32 0, i32 11, i32 undef
br i1 %cmp407, label %if.then409, label %if.end437
if.then409: ; preds = %for.body405
%arrayidx416 = getelementptr inbounds [40 x i16], [40 x i16]* null, i32 0, i32 undef
%7 = load i16, i16* %arrayidx416, align 2
%conv417 = sext i16 %7 to i32
%shl = shl i32 %conv417, 4
%mul419 = mul nsw i32 %shl, 655
%add420 = add nsw i32 %mul419, 0
br label %if.end437
if.end437: ; preds = %if.then409, %for.body405
%mul431.sink = phi i32 [ %add420, %if.then409 ], [ undef, %for.body405 ]
%shr432257 = lshr i32 %mul431.sink, 15
%conv433 = trunc i32 %shr432257 to i16
store i16 %conv433, i16* %arrayidx412, align 2
br label %for.body405
}
attributes #0 = { noinline nounwind "target-cpu"="hexagonv60" "target-features"="-hvx,-long-calls" }

View File

@@ -0,0 +1,62 @@
; RUN: opt -march=hexagon -hexagon-loop-idiom -S < %s | FileCheck %s
;
; The number of nested selects caused the simplification loop to take
; more than the maximum number of iterations. This caused the compiler
; to crash under suspicion of an infinite loop. This (still reduced)
; testcase shows a legitimate case where this limit was exceeded.
; Instead of crashing, gracefully abort the simplification.
;
; Check for sane output.
; CHECK: define void @fred
target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048"
target triple = "hexagon"
define void @fred() unnamed_addr #0 {
b0:
%v1 = select i1 false, i32 undef, i32 2
br label %b2
b2: ; preds = %b2, %b0
%v3 = sext i16 undef to i32
%v4 = add nsw i32 %v1, %v3
%v5 = select i1 undef, i32 undef, i32 %v4
%v6 = icmp slt i32 %v5, undef
%v7 = select i1 %v6, i32 %v5, i32 undef
%v8 = icmp slt i32 %v7, 0
%v9 = select i1 %v8, i32 %v7, i32 0
%v10 = sub i32 undef, undef
%v11 = add i32 %v10, %v9
%v12 = sext i16 undef to i32
%v13 = sext i16 undef to i32
%v14 = add nsw i32 %v1, %v13
%v15 = select i1 undef, i32 undef, i32 %v14
%v16 = icmp slt i32 %v15, undef
%v17 = select i1 %v16, i32 %v15, i32 undef
%v18 = select i1 undef, i32 %v17, i32 %v12
%v19 = add i32 undef, %v18
%v20 = sext i16 undef to i32
%v21 = sext i16 0 to i32
%v22 = add nsw i32 %v1, %v21
%v23 = sext i16 undef to i32
%v24 = add nsw i32 %v1, %v23
%v25 = select i1 undef, i32 undef, i32 %v24
%v26 = icmp slt i32 %v25, %v22
%v27 = select i1 %v26, i32 %v25, i32 %v22
%v28 = icmp slt i32 %v27, %v20
%v29 = select i1 %v28, i32 %v27, i32 %v20
%v30 = add i32 undef, %v29
%v31 = add i32 %v11, undef
%v32 = add i32 %v31, undef
%v33 = add i32 %v32, %v19
%v34 = add i32 %v33, %v30
%v35 = add nsw i32 %v34, 32768
%v36 = icmp ult i32 %v35, 65536
%v37 = select i1 %v36, i32 %v34, i32 undef
br i1 undef, label %b2, label %b38
b38: ; preds = %b2
unreachable
}
attributes #0 = { "target-cpu"="hexagonv60" }

View File

@@ -0,0 +1,84 @@
; Run -O2 to make sure that all the usual optimizations do happen before
; the Hexagon loop idiom recognition runs. This is to check that we still
; get this opportunity regardless of what happens before.
; RUN: opt -O2 -march=hexagon -S < %s | FileCheck %s
target triple = "hexagon"
target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048"
; CHECK-LABEL: define zeroext i16 @pmpy_mod_lsr
; There need to be two pmpy instructions.
; CHECK: call i64 @llvm.hexagon.M4.pmpyw
; CHECK: call i64 @llvm.hexagon.M4.pmpyw
define zeroext i16 @pmpy_mod_lsr(i8 zeroext %a0, i16 zeroext %a1) #0 {
b2:
br label %b3
b3: ; preds = %b44, %b2
%v4 = phi i8 [ %a0, %b2 ], [ %v19, %b44 ]
%v5 = phi i16 [ %a1, %b2 ], [ %v43, %b44 ]
%v6 = phi i8 [ 0, %b2 ], [ %v45, %b44 ]
%v7 = zext i8 %v6 to i32
%v8 = icmp slt i32 %v7, 8
br i1 %v8, label %b9, label %b46
b9: ; preds = %b3
%v10 = zext i8 %v4 to i32
%v11 = and i32 %v10, 1
%v12 = trunc i16 %v5 to i8
%v13 = zext i8 %v12 to i32
%v14 = and i32 %v13, 1
%v15 = xor i32 %v11, %v14
%v16 = trunc i32 %v15 to i8
%v17 = zext i8 %v4 to i32
%v18 = ashr i32 %v17, 1
%v19 = trunc i32 %v18 to i8
%v20 = zext i8 %v16 to i32
%v21 = icmp eq i32 %v20, 1
br i1 %v21, label %b22, label %b26
b22: ; preds = %b9
%v23 = zext i16 %v5 to i32
%v24 = xor i32 %v23, 16386
%v25 = trunc i32 %v24 to i16
br label %b27
b26: ; preds = %b9
br label %b27
b27: ; preds = %b26, %b22
%v28 = phi i16 [ %v25, %b22 ], [ %v5, %b26 ]
%v29 = phi i8 [ 1, %b22 ], [ 0, %b26 ]
%v30 = zext i16 %v28 to i32
%v31 = ashr i32 %v30, 1
%v32 = trunc i32 %v31 to i16
%v33 = icmp ne i8 %v29, 0
br i1 %v33, label %b34, label %b38
b34: ; preds = %b27
%v35 = zext i16 %v32 to i32
%v36 = or i32 %v35, 32768
%v37 = trunc i32 %v36 to i16
br label %b42
b38: ; preds = %b27
%v39 = zext i16 %v32 to i32
%v40 = and i32 %v39, 32767
%v41 = trunc i32 %v40 to i16
br label %b42
b42: ; preds = %b38, %b34
%v43 = phi i16 [ %v37, %b34 ], [ %v41, %b38 ]
br label %b44
b44: ; preds = %b42
%v45 = add i8 %v6, 1
br label %b3
b46: ; preds = %b3
ret i16 %v5
}
attributes #0 = { noinline nounwind "target-cpu"="hexagonv5" "target-features"="-hvx,-long-calls" }

View File

@@ -0,0 +1,48 @@
; RUN: opt -march=hexagon -hexagon-loop-idiom -S < %s | FileCheck %s
; REQUIRES: asserts
;
; Check for sane output, this used to crash.
; CHECK: define void @fred
; The conversion of shifts from right to left failed, but the return
; code was not checked and the transformation proceeded.
target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048"
target triple = "hexagon"
@A = common global [256 x i32] zeroinitializer, align 8
; Function Attrs: noinline nounwind
define void @fred() local_unnamed_addr #0 {
b0:
br label %b1
b1: ; preds = %b13, %b0
%v2 = phi i32 [ 0, %b0 ], [ %v16, %b13 ]
br label %b3
b3: ; preds = %b3, %b1
%v4 = phi i32 [ %v2, %b1 ], [ %v10, %b3 ]
%v5 = phi i32 [ 0, %b1 ], [ %v11, %b3 ]
%v6 = and i32 %v4, 1
%v7 = icmp ne i32 %v6, 0
%v8 = lshr i32 %v4, 1
%v9 = xor i32 %v8, 123456789
%v10 = select i1 %v7, i32 %v9, i32 %v8
%v11 = add nuw nsw i32 %v5, 1
%v12 = icmp ne i32 %v11, 8
br i1 %v12, label %b3, label %b13
b13: ; preds = %b3
%v14 = phi i32 [ %v10, %b3 ]
%v15 = getelementptr inbounds [256 x i32], [256 x i32]* @A, i32 0, i32 %v2
store i32 %v14, i32* %v15, align 4
%v16 = add nuw nsw i32 %v2, 1
%v17 = icmp ne i32 %v16, 256
br i1 %v17, label %b1, label %b18
b18: ; preds = %b13
ret void
}
attributes #0 = { noinline nounwind "target-cpu"="hexagonv60" }

View File

@@ -0,0 +1,33 @@
; RUN: opt -hexagon-loop-idiom < %s -mtriple=hexagon-unknown-unknown -S \
; RUN: | FileCheck %s
target triple = "hexagon"
; CHECK: define i64 @basic_pmpy
; CHECK: llvm.hexagon.M4.pmpyw
define i64 @basic_pmpy(i32 %P, i32 %Q) #0 {
entry:
%conv = zext i32 %Q to i64
br label %for.body
for.body: ; preds = %entry, %for.body
%i.07 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
%R.06 = phi i64 [ 0, %entry ], [ %xor.R.06, %for.body ]
%shl = shl i32 1, %i.07
%and = and i32 %shl, %P
%tobool = icmp eq i32 %and, 0
%sh_prom = zext i32 %i.07 to i64
%shl1 = shl i64 %conv, %sh_prom
%xor = xor i64 %shl1, %R.06
%xor.R.06 = select i1 %tobool, i64 %R.06, i64 %xor
%inc = add nuw nsw i32 %i.07, 1
%exitcond = icmp ne i32 %inc, 32
br i1 %exitcond, label %for.body, label %for.end
for.end: ; preds = %for.body
%R.1.lcssa = phi i64 [ %xor.R.06, %for.body ]
ret i64 %R.1.lcssa
}
attributes #0 = { nounwind }