diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2675,14 +2675,7 @@ intersectAccessGroups(K, J)); break; case LLVMContext::MD_range: - - // If K does move, use most generic range. Otherwise keep the range of - // K. - if (DoesKMove) - // FIXME: If K does move, we should drop the range info and nonnull. - // Currently this function is used with DoesKMove in passes - // doing hoisting/sinking and the current behavior of using the - // most generic range is correct in those cases. + if (DoesKMove || !J->hasMetadata(LLVMContext::MD_noundef)) K->setMetadata(Kind, MDNode::getMostGenericRange(JMD, KMD)); break; case LLVMContext::MD_fpmath: diff --git a/llvm/test/Transforms/GVN/range.ll b/llvm/test/Transforms/GVN/range.ll --- a/llvm/test/Transforms/GVN/range.ll +++ b/llvm/test/Transforms/GVN/range.ll @@ -12,7 +12,7 @@ define i32 @test2(ptr %p) { ; CHECK-LABEL: @test2(ptr %p) -; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE0]] +; CHECK: %a = load i32, ptr %p, align 4 ; CHECK: %c = add i32 %a, %a %a = load i32, ptr %p, !range !0 %b = load i32, ptr %p @@ -22,7 +22,7 @@ define i32 @test3(ptr %p) { ; CHECK-LABEL: @test3(ptr %p) -; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE0]] +; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE1:[0-9]+]] ; CHECK: %c = add i32 %a, %a %a = load i32, ptr %p, !range !0 %b = load i32, ptr %p, !range !1 @@ -32,7 +32,7 @@ define i32 @test4(ptr %p) { ; CHECK-LABEL: @test4(ptr %p) -; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE0]] +; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE2:[0-9]+]] ; CHECK: %c = add i32 %a, %a %a = load i32, ptr %p, !range !0 %b = load i32, ptr %p, !range !2 @@ -52,7 +52,7 @@ define i32 @test6(ptr %p) { ; CHECK-LABEL: @test6(ptr %p) -; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE5:[0-9]+]] +; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE4:[0-9]+]] ; CHECK: %c = add i32 %a, %a %a = load i32, ptr %p, !range !5 %b = load i32, ptr %p, !range !6 @@ -62,7 +62,7 @@ define i32 @test7(ptr %p) { ; CHECK-LABEL: @test7(ptr %p) -; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE7:[0-9]+]] +; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE5:[0-9]+]] ; CHECK: %c = add i32 %a, %a %a = load i32, ptr %p, !range !7 %b = load i32, ptr %p, !range !8 @@ -72,7 +72,7 @@ define i32 @test8(ptr %p) { ; CHECK-LABEL: @test8(ptr %p) -; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE9:[0-9]+]] +; CHECK: %a = load i32, ptr %p, align 4 ; CHECK-NOT: range ; CHECK: %c = add i32 %a, %a %a = load i32, ptr %p, !range !9 @@ -82,10 +82,11 @@ } ; CHECK: ![[RANGE0]] = !{i32 0, i32 2} -; CHECK: ![[RANGE3]] = !{i32 -5, i32 -2} -; CHECK: ![[RANGE5]] = !{i32 10, i32 1} -; CHECK: ![[RANGE7]] = !{i32 1, i32 2, i32 3, i32 4} -; CHECK: ![[RANGE9]] = !{i32 1, i32 5} +; CHECK: ![[RANGE1]] = !{i32 0, i32 2, i32 3, i32 5} +; CHECK: ![[RANGE2]] = !{i32 0, i32 5} +; CHECK: ![[RANGE3]] = !{i32 -5, i32 -2, i32 1, i32 5} +; CHECK: ![[RANGE4]] = !{i32 10, i32 1} +; CHECK: ![[RANGE5]] = !{i32 3, i32 4, i32 5, i32 2} !0 = !{i32 0, i32 2} !1 = !{i32 3, i32 5} diff --git a/llvm/test/Transforms/JumpThreading/thread-loads.ll b/llvm/test/Transforms/JumpThreading/thread-loads.ll --- a/llvm/test/Transforms/JumpThreading/thread-loads.ll +++ b/llvm/test/Transforms/JumpThreading/thread-loads.ll @@ -321,9 +321,13 @@ ; branch. define void @test8(ptr, ptr, ptr) { ; CHECK-LABEL: @test8( -; CHECK-NEXT: ret2: ; CHECK-NEXT: [[A:%.*]] = load i32, ptr [[TMP0:%.*]], align 4, !range [[RNG4:![0-9]+]] ; CHECK-NEXT: store i32 [[A]], ptr [[TMP1:%.*]], align 4 +; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[A]], 8 +; CHECK-NEXT: br i1 [[C]], label [[RET1:%.*]], label [[RET2:%.*]] +; CHECK: ret1: +; CHECK-NEXT: ret void +; CHECK: ret2: ; CHECK-NEXT: [[XXX:%.*]] = tail call i32 (...) @f1() #[[ATTR0]] ; CHECK-NEXT: ret void ; @@ -679,8 +683,7 @@ ret i32 10 } - -; CHECK: [[RNG4]] = !{i32 0, i32 1} +; CHECK: [[RNG4]] = !{i32 0, i32 1, i32 8, i32 10} !0 = !{!3, !3, i64 0} !1 = !{!"omnipotent char", !2} diff --git a/llvm/test/Transforms/NewGVN/range.ll b/llvm/test/Transforms/NewGVN/range.ll --- a/llvm/test/Transforms/NewGVN/range.ll +++ b/llvm/test/Transforms/NewGVN/range.ll @@ -12,7 +12,7 @@ define i32 @test2(ptr %p) { ; CHECK-LABEL: @test2(ptr %p) -; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE0]] +; CHECK: %a = load i32, ptr %p, align 4 ; CHECK: %c = add i32 %a, %a %a = load i32, ptr %p, !range !0 %b = load i32, ptr %p @@ -22,7 +22,7 @@ define i32 @test3(ptr %p) { ; CHECK-LABEL: @test3(ptr %p) -; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE0]] +; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE1:[0-9]+]] ; CHECK: %c = add i32 %a, %a %a = load i32, ptr %p, !range !0 %b = load i32, ptr %p, !range !1 @@ -32,7 +32,7 @@ define i32 @test4(ptr %p) { ; CHECK-LABEL: @test4(ptr %p) -; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE0]] +; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE2:[0-9]+]] ; CHECK: %c = add i32 %a, %a %a = load i32, ptr %p, !range !0 %b = load i32, ptr %p, !range !2 @@ -52,7 +52,7 @@ define i32 @test6(ptr %p) { ; CHECK-LABEL: @test6(ptr %p) -; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE5:[0-9]+]] +; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE4:[0-9]+]] ; CHECK: %c = add i32 %a, %a %a = load i32, ptr %p, !range !5 %b = load i32, ptr %p, !range !6 @@ -62,7 +62,7 @@ define i32 @test7(ptr %p) { ; CHECK-LABEL: @test7(ptr %p) -; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE7:[0-9]+]] +; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE5:[0-9]+]] ; CHECK: %c = add i32 %a, %a %a = load i32, ptr %p, !range !7 %b = load i32, ptr %p, !range !8 @@ -72,7 +72,7 @@ define i32 @test8(ptr %p) { ; CHECK-LABEL: @test8(ptr %p) -; CHECK: %a = load i32, ptr %p, align 4, !range ![[RANGE9:[0-9]+]] +; CHECK: %a = load i32, ptr %p, align 4 ; CHECK-NOT: range ; CHECK: %c = add i32 %a, %a %a = load i32, ptr %p, !range !9 @@ -82,10 +82,11 @@ } ; CHECK: ![[RANGE0]] = !{i32 0, i32 2} -; CHECK: ![[RANGE3]] = !{i32 -5, i32 -2} -; CHECK: ![[RANGE5]] = !{i32 10, i32 1} -; CHECK: ![[RANGE7]] = !{i32 1, i32 2, i32 3, i32 4} -; CHECK: ![[RANGE9]] = !{i32 1, i32 5} +; CHECK: ![[RANGE1]] = !{i32 0, i32 2, i32 3, i32 5} +; CHECK: ![[RANGE2]] = !{i32 0, i32 5} +; CHECK: ![[RANGE3]] = !{i32 -5, i32 -2, i32 1, i32 5} +; CHECK: ![[RANGE4]] = !{i32 10, i32 1} +; CHECK: ![[RANGE5]] = !{i32 3, i32 4, i32 5, i32 2} !0 = !{i32 0, i32 2} !1 = !{i32 3, i32 5}