87 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 42; RUN: opt -S -passes=loop-vectorize < %s | FileCheck %s3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"4target triple = "x86_64-unknown-linux-gnu"5 6; PR 81872 explains the issue.7 8; If we vectorize, we have a miscompile where array IV and thereby value stored in (arr[99],9; arr[98]) is calculated incorrectly since disjoint or was only disjoint because10; of dominating conditions. Dropping the disjoint to avoid poison still changes11; the behaviour since now the or is no longer equivalent to the add.12;13define void @test(ptr noundef align 8 dereferenceable_or_null(16) %arr) #0 {14; CHECK-LABEL: define void @test(15; CHECK-SAME: ptr noundef align 8 dereferenceable_or_null(16) [[ARR:%.*]]) #[[ATTR0:[0-9]+]] {16; CHECK-NEXT: bb5:17; CHECK-NEXT: br label [[VECTOR_PH:%.*]]18; CHECK: vector.ph:19; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]20; CHECK: vector.body:21; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]22; CHECK-NEXT: [[VEC_IND:%.*]] = phi <4 x i64> [ <i64 99, i64 98, i64 97, i64 96>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]23; CHECK-NEXT: [[OFFSET_IDX:%.*]] = sub i64 99, [[INDEX]]24; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[INDEX]], i64 025; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer26; CHECK-NEXT: [[VEC_IV:%.*]] = add <4 x i64> [[BROADCAST_SPLAT]], <i64 0, i64 1, i64 2, i64 3>27; CHECK-NEXT: [[TMP1:%.*]] = icmp ule <4 x i64> [[VEC_IV]], splat (i64 8)28; CHECK-NEXT: [[TMP2:%.*]] = and <4 x i64> [[VEC_IND]], splat (i64 1)29; CHECK-NEXT: [[TMP3:%.*]] = icmp eq <4 x i64> [[TMP2]], zeroinitializer30; CHECK-NEXT: [[TMP4:%.*]] = select <4 x i1> [[TMP1]], <4 x i1> [[TMP3]], <4 x i1> zeroinitializer31; CHECK-NEXT: [[TMP5:%.*]] = add i64 [[OFFSET_IDX]], 132; CHECK-NEXT: [[TMP6:%.*]] = getelementptr i64, ptr [[ARR]], i64 [[TMP5]]33; CHECK-NEXT: [[TMP7:%.*]] = getelementptr i64, ptr [[TMP6]], i64 034; CHECK-NEXT: [[TMP8:%.*]] = getelementptr i64, ptr [[TMP7]], i64 -335; CHECK-NEXT: [[REVERSE:%.*]] = shufflevector <4 x i1> [[TMP4]], <4 x i1> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>36; CHECK-NEXT: call void @llvm.masked.store.v4i64.p0(<4 x i64> splat (i64 1), ptr align 8 [[TMP8]], <4 x i1> [[REVERSE]])37; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 438; CHECK-NEXT: [[VEC_IND_NEXT]] = add nsw <4 x i64> [[VEC_IND]], splat (i64 -4)39; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1240; CHECK-NEXT: br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !prof [[PROF0:![0-9]+]], !llvm.loop [[LOOP1:![0-9]+]]41; CHECK: middle.block:42; CHECK-NEXT: br label [[LOOP_LATCH:%.*]]43; CHECK: bb6:44; CHECK-NEXT: ret void45;46bb5:47 br label %loop.header48 49loop.header: ; preds = %loop.latch, %bb850 %iv = phi i64 [ 99, %bb5 ], [ %iv.next, %loop.latch ]51 %and = and i64 %iv, 152 %icmp17 = icmp eq i64 %and, 053 br i1 %icmp17, label %bb18, label %loop.latch, !prof !2154 55bb18: ; preds = %loop.header56 %or = or disjoint i64 %iv, 157 %getelementptr19 = getelementptr inbounds i64, ptr %arr, i64 %or58 store i64 1, ptr %getelementptr19, align 859 br label %loop.latch60 61loop.latch: ; preds = %bb18, %loop.header62 %iv.next = add nsw i64 %iv, -163 %icmp22 = icmp eq i64 %iv.next, 9064 br i1 %icmp22, label %bb6, label %loop.header, !prof !2265 66bb6:67 ret void68}69 70attributes #0 = {"target-cpu"="haswell" "target-features"="+avx2" }71 72!4 = !{}73!10 = !{i32 1}74!16 = !{i64 864}75!17 = !{i64 8}76!21 = !{!"branch_weights", i32 1, i32 1}77!22 = !{!"branch_weights", i32 1, i32 95}78 79 80;.81; CHECK: [[PROF0]] = !{!"branch_weights", i32 1, i32 23}82; CHECK: [[LOOP1]] = distinct !{[[LOOP1]], [[META2:![0-9]+]], [[META3:![0-9]+]], [[META4:![0-9]+]]}83; CHECK: [[META2]] = !{!"llvm.loop.isvectorized", i32 1}84; CHECK: [[META3]] = !{!"llvm.loop.unroll.runtime.disable"}85; CHECK: [[META4]] = !{!"llvm.loop.estimated_trip_count", i32 24}86;.87