blob: b4979017b67e81f51de9296c1dc30b7c6ce46104 [file] [edit]
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
; RUN: opt -S -passes=jump-threading < %s | FileCheck %s
; Threading a loop exit (via cloneInstructions) must clone the block's noalias
; scope declarations so the threaded copy does not share the original's scopes.
define void @test(ptr %ptr) {
; CHECK-LABEL: @test(
; CHECK-NEXT: entry:
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata [[META0:![0-9]+]])
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_INC:%.*]], [[LATCH:%.*]] ]
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[I]], 100
; CHECK-NEXT: br i1 [[C]], label [[EXIT:%.*]], label [[LATCH]]
; CHECK: latch:
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata [[META3:![0-9]+]])
; CHECK-NEXT: store i8 0, ptr [[PTR:%.*]], align 1, !noalias [[META0]]
; CHECK-NEXT: store i8 1, ptr [[PTR]], align 1, !noalias [[META3]]
; CHECK-NEXT: [[I_INC]] = add i32 [[I]], 1
; CHECK-NEXT: br label [[LOOP]]
; CHECK: exit:
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata [[META5:![0-9]+]])
; CHECK-NEXT: store i8 0, ptr [[PTR]], align 1, !noalias [[META0]]
; CHECK-NEXT: store i8 1, ptr [[PTR]], align 1, !noalias [[META5]]
; CHECK-NEXT: ret void
;
entry:
call void @llvm.experimental.noalias.scope.decl(metadata !0)
br label %loop
loop:
%i = phi i32 [ 0, %entry ], [ %i.inc, %latch ]
%c = icmp eq i32 %i, 100
br i1 %c, label %if, label %latch
if:
br label %latch
latch:
%p = phi i1 [ true, %if ], [ false, %loop ]
call void @llvm.experimental.noalias.scope.decl(metadata !3)
store i8 0, ptr %ptr, !noalias !0
store i8 1, ptr %ptr, !noalias !3
%i.inc = add i32 %i, 1
br i1 %p, label %exit, label %loop
exit:
ret void
}
; duplicateCondBranchOnPHIIntoPred duplicates a block whose conditional branch
; is on a PHI of non-constant values into a predecessor. It must likewise clone
; the block's noalias scope declarations, otherwise the duplicate shares the
; original's scope MDNodes and alias analysis can wrongly conclude two accesses
; on different paths do not alias.
define void @dup_clones_noalias_scope(ptr %p) {
; CHECK-LABEL: @dup_clones_noalias_scope(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C:%.*]] = call i1 @opaque()
; CHECK-NEXT: br i1 [[C]], label [[PRED:%.*]], label [[BB:%.*]]
; CHECK: pred:
; CHECK-NEXT: [[PV:%.*]] = call i1 @opaque()
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata [[META7:![0-9]+]])
; CHECK-NEXT: store i8 0, ptr [[P:%.*]], align 1, !noalias [[META7]]
; CHECK-NEXT: br i1 [[PV]], label [[TB:%.*]], label [[FB:%.*]]
; CHECK: bb:
; CHECK-NEXT: [[OV:%.*]] = call i1 @opaque()
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata [[META0]])
; CHECK-NEXT: store i8 0, ptr [[P]], align 1, !noalias [[META0]]
; CHECK-NEXT: br i1 [[OV]], label [[TB]], label [[FB]]
; CHECK: tb:
; CHECK-NEXT: ret void
; CHECK: fb:
; CHECK-NEXT: ret void
;
entry:
%c = call i1 @opaque()
br i1 %c, label %pred, label %other
pred:
%pv = call i1 @opaque()
br label %bb
other:
%ov = call i1 @opaque()
br label %bb
bb:
%x = phi i1 [ %pv, %pred ], [ %ov, %other ]
call void @llvm.experimental.noalias.scope.decl(metadata !0)
store i8 0, ptr %p, !noalias !0
br i1 %x, label %tb, label %fb
tb:
ret void
fb:
ret void
}
declare i1 @opaque()
declare void @llvm.experimental.noalias.scope.decl(metadata)
!0 = !{!1}
!1 = distinct !{!1, !2, !"scope1"}
!2 = distinct !{!2, !"domain"}
!3 = !{!4}
!4 = distinct !{!4, !2, !"scope2"}
;.
; CHECK: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
;.
; CHECK: [[META0]] = !{[[META1:![0-9]+]]}
; CHECK: [[META1]] = distinct !{[[META1]], [[META2:![0-9]+]], !"scope1"}
; CHECK: [[META2]] = distinct !{[[META2]], !"domain"}
; CHECK: [[META3]] = !{[[META4:![0-9]+]]}
; CHECK: [[META4]] = distinct !{[[META4]], [[META2]], !"scope2"}
; CHECK: [[META5]] = !{[[META6:![0-9]+]]}
; CHECK: [[META6]] = distinct !{[[META6]], [[META2]], !"scope2:thread"}
; CHECK: [[META7]] = !{[[META8:![0-9]+]]}
; CHECK: [[META8]] = distinct !{[[META8]], [[META2]], !"scope1:thread"}
;.