[llvm] 05ef449 - [SimplifyCFG] Handle MD_noundef when hoisting common codes

via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 3 03:04:12 PST 2023


Author: luxufan
Date: 2023-03-03T19:02:14+08:00
New Revision: 05ef449600be9e14ce8d88a22fdf1f76eb8cd4b4

URL: https://github.com/llvm/llvm-project/commit/05ef449600be9e14ce8d88a22fdf1f76eb8cd4b4
DIFF: https://github.com/llvm/llvm-project/commit/05ef449600be9e14ce8d88a22fdf1f76eb8cd4b4.diff

LOG: [SimplifyCFG] Handle MD_noundef when hoisting common codes

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D144939

Added: 
    llvm/test/Transforms/SimplifyCFG/hoist-with-metadata.ll

Modified: 
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Removed: 
    llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 747db1f5c63f5..28a09e820d6ca 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1619,19 +1619,7 @@ bool SimplifyCFGOpt::HoistThenElseCodeToIf(BranchInst *BI,
         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
index 0000000000000..63ffdbb5a90d3
--- /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
index 56060baf3ceb0..0000000000000
--- 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 }


        


More information about the llvm-commits mailing list