|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4 |
| 2 | +; RUN: opt -S -passes=loop-vectorize < %s | FileCheck %s |
| 3 | +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 4 | +target triple = "x86_64-unknown-linux-gnu" |
| 5 | + |
| 6 | +@global = external global ptr addrspace(1), align 8 |
| 7 | + |
| 8 | +; PR 81872 explains the issue. |
| 9 | + |
| 10 | +; If we vectorize, we have a miscompile where array IV and thereby value stored in (arr[99], |
| 11 | +; arr[98]) is calculated incorrectly since disjoint or was only disjoint because |
| 12 | +; of dominating conditions. Dropping the disjoint to avoid poison still changes |
| 13 | +; the behaviour since now the or is no longer equivalent to the add. |
| 14 | +; Function Attrs: uwtable |
| 15 | +define void @test(ptr noundef align 8 dereferenceable_or_null(16) %arr) #0 { |
| 16 | +; CHECK-LABEL: define void @test( |
| 17 | +; CHECK-SAME: ptr noundef align 8 dereferenceable_or_null(16) [[ARR:%.*]]) #[[ATTR0:[0-9]+]] { |
| 18 | +; CHECK-NEXT: bb5: |
| 19 | +; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]], !prof [[PROF0:![0-9]+]] |
| 20 | +; CHECK: vector.ph: |
| 21 | +; CHECK-NEXT: br label [[VECTOR_BODY:%.*]] |
| 22 | +; CHECK: vector.body: |
| 23 | +; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] |
| 24 | +; CHECK-NEXT: [[VEC_IND:%.*]] = phi <4 x i64> [ <i64 99, i64 98, i64 97, i64 96>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ] |
| 25 | +; CHECK-NEXT: [[OFFSET_IDX:%.*]] = sub i64 99, [[INDEX]] |
| 26 | +; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[OFFSET_IDX]], 0 |
| 27 | +; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[INDEX]], i64 0 |
| 28 | +; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer |
| 29 | +; CHECK-NEXT: [[VEC_IV:%.*]] = add <4 x i64> [[BROADCAST_SPLAT]], <i64 0, i64 1, i64 2, i64 3> |
| 30 | +; CHECK-NEXT: [[TMP1:%.*]] = icmp ule <4 x i64> [[VEC_IV]], <i64 8, i64 8, i64 8, i64 8> |
| 31 | +; CHECK-NEXT: [[TMP2:%.*]] = and <4 x i64> [[VEC_IND]], <i64 1, i64 1, i64 1, i64 1> |
| 32 | +; CHECK-NEXT: [[TMP3:%.*]] = icmp eq <4 x i64> [[TMP2]], zeroinitializer |
| 33 | +; CHECK-NEXT: [[TMP4:%.*]] = select <4 x i1> [[TMP1]], <4 x i1> [[TMP3]], <4 x i1> zeroinitializer |
| 34 | +; CHECK-NEXT: [[TMP5:%.*]] = or i64 [[TMP0]], 1 |
| 35 | +; CHECK-NEXT: [[TMP6:%.*]] = getelementptr i64, ptr [[ARR]], i64 [[TMP5]] |
| 36 | +; CHECK-NEXT: [[TMP7:%.*]] = getelementptr i64, ptr [[TMP6]], i32 0 |
| 37 | +; CHECK-NEXT: [[TMP8:%.*]] = getelementptr i64, ptr [[TMP7]], i32 -3 |
| 38 | +; CHECK-NEXT: [[REVERSE:%.*]] = shufflevector <4 x i1> [[TMP4]], <4 x i1> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0> |
| 39 | +; CHECK-NEXT: call void @llvm.masked.store.v4i64.p0(<4 x i64> <i64 1, i64 1, i64 1, i64 1>, ptr [[TMP8]], i32 8, <4 x i1> [[REVERSE]]) |
| 40 | +; CHECK-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 4 |
| 41 | +; CHECK-NEXT: [[VEC_IND_NEXT]] = add <4 x i64> [[VEC_IND]], <i64 -4, i64 -4, i64 -4, i64 -4> |
| 42 | +; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 12 |
| 43 | +; CHECK-NEXT: br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !prof [[PROF1:![0-9]+]], !llvm.loop [[LOOP2:![0-9]+]] |
| 44 | +; CHECK: middle.block: |
| 45 | +; CHECK-NEXT: br i1 true, label [[BB6:%.*]], label [[SCALAR_PH]] |
| 46 | +; CHECK: scalar.ph: |
| 47 | +; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 87, [[MIDDLE_BLOCK]] ], [ 99, [[BB5:%.*]] ] |
| 48 | +; CHECK-NEXT: br label [[BB15:%.*]] |
| 49 | +; CHECK: bb15: |
| 50 | +; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[BB20:%.*]] ] |
| 51 | +; CHECK-NEXT: [[AND:%.*]] = and i64 [[IV]], 1 |
| 52 | +; CHECK-NEXT: [[ICMP17:%.*]] = icmp eq i64 [[AND]], 0 |
| 53 | +; CHECK-NEXT: br i1 [[ICMP17]], label [[BB18:%.*]], label [[BB20]], !prof [[PROF5:![0-9]+]] |
| 54 | +; CHECK: bb18: |
| 55 | +; CHECK-NEXT: [[OR:%.*]] = or disjoint i64 [[IV]], 1 |
| 56 | +; CHECK-NEXT: [[GETELEMENTPTR19:%.*]] = getelementptr inbounds i64, ptr [[ARR]], i64 [[OR]] |
| 57 | +; CHECK-NEXT: store i64 1, ptr [[GETELEMENTPTR19]], align 8 |
| 58 | +; CHECK-NEXT: br label [[BB20]] |
| 59 | +; CHECK: bb20: |
| 60 | +; CHECK-NEXT: [[IV_NEXT]] = add nsw i64 [[IV]], -1 |
| 61 | +; CHECK-NEXT: [[ICMP22:%.*]] = icmp eq i64 [[IV_NEXT]], 90 |
| 62 | +; CHECK-NEXT: br i1 [[ICMP22]], label [[BB6]], label [[BB15]], !prof [[PROF6:![0-9]+]], !llvm.loop [[LOOP7:![0-9]+]] |
| 63 | +; CHECK: bb6: |
| 64 | +; CHECK-NEXT: ret void |
| 65 | +; |
| 66 | +bb5: |
| 67 | + br label %bb15 |
| 68 | + |
| 69 | +bb15: ; preds = %bb20, %bb8 |
| 70 | + %iv = phi i64 [ 99, %bb5 ], [ %iv.next, %bb20 ] |
| 71 | + %and = and i64 %iv, 1 |
| 72 | + %icmp17 = icmp eq i64 %and, 0 |
| 73 | + br i1 %icmp17, label %bb18, label %bb20, !prof !21 |
| 74 | + |
| 75 | +bb18: ; preds = %bb15 |
| 76 | + %or = or disjoint i64 %iv, 1 |
| 77 | + %getelementptr19 = getelementptr inbounds i64, ptr %arr, i64 %or |
| 78 | + store i64 1, ptr %getelementptr19, align 8 |
| 79 | + br label %bb20 |
| 80 | + |
| 81 | +bb20: ; preds = %bb18, %bb15 |
| 82 | + %iv.next = add nsw i64 %iv, -1 |
| 83 | + %icmp22 = icmp eq i64 %iv.next, 90 |
| 84 | + br i1 %icmp22, label %bb6, label %bb15, !prof !22 |
| 85 | + |
| 86 | +bb6: |
| 87 | + ret void |
| 88 | +} |
| 89 | + |
| 90 | +attributes #0 = {"target-cpu"="haswell" "target-features"="+avx2" } |
| 91 | + |
| 92 | +!4 = !{} |
| 93 | +!10 = !{i32 1} |
| 94 | +!16 = !{i64 864} |
| 95 | +!17 = !{i64 8} |
| 96 | +!21 = !{!"branch_weights", i32 1, i32 1} |
| 97 | +!22 = !{!"branch_weights", i32 1, i32 95} |
| 98 | + |
| 99 | + |
| 100 | +;. |
| 101 | +; CHECK: [[PROF0]] = !{!"branch_weights", i32 1, i32 127} |
| 102 | +; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 23} |
| 103 | +; CHECK: [[LOOP2]] = distinct !{[[LOOP2]], [[META3:![0-9]+]], [[META4:![0-9]+]]} |
| 104 | +; CHECK: [[META3]] = !{!"llvm.loop.isvectorized", i32 1} |
| 105 | +; CHECK: [[META4]] = !{!"llvm.loop.unroll.runtime.disable"} |
| 106 | +; CHECK: [[PROF5]] = !{!"branch_weights", i32 1, i32 1} |
| 107 | +; CHECK: [[PROF6]] = !{!"branch_weights", i32 0, i32 0} |
| 108 | +; CHECK: [[LOOP7]] = distinct !{[[LOOP7]], [[META4]], [[META3]]} |
| 109 | +;. |
0 commit comments