| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4 | |
| ; RUN: opt -S -passes=loop-vectorize < %s | FileCheck %s | |
| target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" | |
| target triple = "x86_64-unknown-linux-gnu" | |
| ; PR 81872 explains the issue. | |
| ; If we vectorize, we have a miscompile where array IV and thereby value stored in (arr[99], | |
| ; arr[98]) is calculated incorrectly since disjoint or was only disjoint because | |
| ; of dominating conditions. Dropping the disjoint to avoid poison still changes | |
| ; the behaviour since now the or is no longer equivalent to the add. | |
| ; | |
| define void @test(ptr noundef align 8 dereferenceable_or_null(16) %arr) #0 { | |
| ; CHECK-LABEL: define void @test( | |
| ; CHECK-SAME: ptr noundef align 8 dereferenceable_or_null(16) [[ARR:%.*]]) #[[ATTR0:[0-9]+]] { | |
| ; CHECK-NEXT: bb5: | |
| ; CHECK-NEXT: br label [[VECTOR_PH:%.*]] | |
| ; CHECK: vector.ph: | |
| ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]] | |
| ; CHECK: vector.body: | |
| ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[VEC_IND:%.*]] = phi <4 x i64> [ <i64 99, i64 98, i64 97, i64 96>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[VEC_IND1:%.*]] = phi <4 x i8> [ <i8 0, i8 1, i8 2, i8 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT2:%.*]], [[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[TMP0:%.*]] = icmp ule <4 x i8> [[VEC_IND1]], splat (i8 14) | |
| ; CHECK-NEXT: [[OFFSET_IDX:%.*]] = sub i64 99, [[INDEX]] | |
| ; CHECK-NEXT: [[TMP1:%.*]] = and <4 x i64> [[VEC_IND]], splat (i64 1) | |
| ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq <4 x i64> [[TMP1]], zeroinitializer | |
| ; CHECK-NEXT: [[TMP3:%.*]] = select <4 x i1> [[TMP0]], <4 x i1> [[TMP2]], <4 x i1> zeroinitializer | |
| ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[OFFSET_IDX]], 1 | |
| ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr i64, ptr [[ARR]], i64 [[TMP4]] | |
| ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr i64, ptr [[TMP5]], i64 -3 | |
| ; CHECK-NEXT: [[REVERSE:%.*]] = shufflevector <4 x i1> [[TMP3]], <4 x i1> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0> | |
| ; CHECK-NEXT: call void @llvm.masked.store.v4i64.p0(<4 x i64> splat (i64 1), ptr align 8 [[TMP6]], <4 x i1> [[REVERSE]]) | |
| ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4 | |
| ; CHECK-NEXT: [[VEC_IND_NEXT]] = add nsw <4 x i64> [[VEC_IND]], splat (i64 -4) | |
| ; CHECK-NEXT: [[VEC_IND_NEXT2]] = add nuw <4 x i8> [[VEC_IND1]], splat (i8 4) | |
| ; CHECK-NEXT: [[TMP7:%.*]] = icmp eq i64 [[INDEX_NEXT]], 16 | |
| ; CHECK-NEXT: br i1 [[TMP7]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !prof [[PROF0:![0-9]+]], !llvm.loop [[LOOP1:![0-9]+]] | |
| ; CHECK: middle.block: | |
| ; CHECK-NEXT: br label [[BB6:%.*]] | |
| ; CHECK: bb6: | |
| ; CHECK-NEXT: ret void | |
| ; | |
| bb5: | |
| br label %loop.header | |
| loop.header: | |
| %iv = phi i64 [ 99, %bb5 ], [ %iv.next, %loop.latch ] | |
| %and = and i64 %iv, 1 | |
| %icmp17 = icmp eq i64 %and, 0 | |
| br i1 %icmp17, label %bb18, label %loop.latch, !prof !21 | |
| bb18: | |
| %or = or disjoint i64 %iv, 1 | |
| %getelementptr19 = getelementptr inbounds i64, ptr %arr, i64 %or | |
| store i64 1, ptr %getelementptr19, align 8 | |
| br label %loop.latch | |
| loop.latch: | |
| %iv.next = add nsw i64 %iv, -1 | |
| %icmp22 = icmp eq i64 %iv.next, 84 | |
| br i1 %icmp22, label %bb6, label %loop.header, !prof !22 | |
| bb6: | |
| ret void | |
| } | |
| attributes #0 = {"target-cpu"="haswell" "target-features"="+avx2" } | |
| !4 = !{} | |
| !10 = !{i32 1} | |
| !16 = !{i64 864} | |
| !17 = !{i64 8} | |
| !21 = !{!"branch_weights", i32 1, i32 1} | |
| !22 = !{!"branch_weights", i32 1, i32 95} | |
| ;. | |
| ; CHECK: [[PROF0]] = !{!"branch_weights", i32 1, i32 23} | |
| ; CHECK: [[LOOP1]] = distinct !{[[LOOP1]], [[META2:![0-9]+]], [[META3:![0-9]+]], [[META4:![0-9]+]]} | |
| ; CHECK: [[META2]] = !{!"llvm.loop.isvectorized", i32 1} | |
| ; CHECK: [[META3]] = !{!"llvm.loop.unroll.runtime.disable"} | |
| ; CHECK: [[META4]] = !{!"llvm.loop.estimated_trip_count", i32 24} | |
| ;. |