diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1619,19 +1619,7 @@ if (!I2->use_empty()) I2->replaceAllUsesWith(I1); I1->andIRFlags(I2); - unsigned KnownIDs[] = {LLVMContext::MD_tbaa, - LLVMContext::MD_range, - LLVMContext::MD_fpmath, - LLVMContext::MD_invariant_load, - LLVMContext::MD_nonnull, - LLVMContext::MD_invariant_group, - LLVMContext::MD_align, - LLVMContext::MD_dereferenceable, - LLVMContext::MD_dereferenceable_or_null, - LLVMContext::MD_mem_parallel_loop_access, - LLVMContext::MD_access_group, - LLVMContext::MD_preserve_access_index}; - combineMetadata(I1, I2, KnownIDs, true); + combineMetadataForCSE(I1, I2, true); // I1 and I2 are being combined into a single instruction. Its debug // location is the merged locations of the original instructions. diff --git a/llvm/test/Transforms/SimplifyCFG/hoist-with-metadata.ll b/llvm/test/Transforms/SimplifyCFG/hoist-with-metadata.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/SimplifyCFG/hoist-with-metadata.ll @@ -0,0 +1,70 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals +; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -S | FileCheck %s + +define void @foo(i1 %c, ptr %p) { +; CHECK-LABEL: @foo( +; CHECK-NEXT: if: +; CHECK-NEXT: [[T:%.*]] = load i8, ptr [[P:%.*]], align 1, !range [[RNG0:![0-9]+]] +; CHECK-NEXT: ret void +; +if: + br i1 %c, label %then, label %else +then: + %t = load i8, ptr %p, !range !0 + br label %out +else: + %e = load i8, ptr %p, !range !1 + br label %out +out: + ret void +} + +define void @md_noundef_combine(i1 %c, ptr %p) { +; CHECK-LABEL: @md_noundef_combine( +; CHECK-NEXT: if: +; CHECK-NEXT: [[T:%.*]] = load i8, ptr [[P:%.*]], align 1, !noundef !1 +; CHECK-NEXT: ret void +; +if: + br i1 %c, label %then, label %else + +then: + %t = load i8, ptr %p, !noundef !2 + br label %out + +else: + %e = load i8, ptr %p, !noundef !2 + br label %out + +out: + ret void +} + +define void @md_noundef_dont_combine(i1 %c, ptr %p) { +; CHECK-LABEL: @md_noundef_dont_combine( +; CHECK-NEXT: if: +; CHECK-NEXT: [[T:%.*]] = load i8, ptr [[P:%.*]], align 1 +; CHECK-NEXT: ret void +; +if: + br i1 %c, label %then, label %else + +then: + %t = load i8, ptr %p, !noundef !2 + br label %out + +else: + %e = load i8, ptr %p + br label %out + +out: + ret void +} + +!0 = !{ i8 0, i8 1 } +!1 = !{ i8 3, i8 5 } +!2 = !{} +;. +; CHECK: [[RNG0]] = !{i8 0, i8 1, i8 3, i8 5} +; CHECK: [[META1:![0-9]+]] = !{} +;. diff --git a/llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll b/llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll deleted file mode 100644 --- a/llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll +++ /dev/null @@ -1,20 +0,0 @@ -; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -S | FileCheck %s - -define void @foo(i1 %c, ptr %p) { -; CHECK: if: -; CHECK-NEXT: load i8, ptr %p, align 1, !range !0 -; CHECK: !0 = !{i8 0, i8 1, i8 3, i8 5} -if: - br i1 %c, label %then, label %else -then: - %t = load i8, ptr %p, !range !0 - br label %out -else: - %e = load i8, ptr %p, !range !1 - br label %out -out: - ret void -} - -!0 = !{ i8 0, i8 1 } -!1 = !{ i8 3, i8 5 }