[llvm-branch-commits] [llvm] 00b733e - [Local] Preserve !align if K dominates J and K has a !noundef

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Mar 30 22:45:28 PDT 2023


Author: luxufan
Date: 2023-03-31T13:44:56+08:00
New Revision: 00b733e20092788b34c38e651f418d1e82fd506e

URL: https://github.com/llvm/llvm-project/commit/00b733e20092788b34c38e651f418d1e82fd506e
DIFF: https://github.com/llvm/llvm-project/commit/00b733e20092788b34c38e651f418d1e82fd506e.diff

LOG: [Local] Preserve !align if K dominates J and K has a !noundef

Similar to D142687

Reviewed By: nikic

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

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/Local.cpp
    llvm/test/Transforms/InstCombine/load-combine-metadata-dominance.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index c7b1dc951752..47088aa23a4e 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -2693,8 +2693,9 @@ void llvm::combineMetadata(Instruction *K, const Instruction *J,
         // Preserve !invariant.group in K.
         break;
       case LLVMContext::MD_align:
-        K->setMetadata(Kind,
-          MDNode::getMostGenericAlignmentOrDereferenceable(JMD, KMD));
+        if (DoesKMove || !K->hasMetadata(LLVMContext::MD_noundef))
+          K->setMetadata(
+              Kind, MDNode::getMostGenericAlignmentOrDereferenceable(JMD, KMD));
         break;
       case LLVMContext::MD_dereferenceable:
       case LLVMContext::MD_dereferenceable_or_null:

diff  --git a/llvm/test/Transforms/InstCombine/load-combine-metadata-dominance.ll b/llvm/test/Transforms/InstCombine/load-combine-metadata-dominance.ll
index 5f86c16b17a7..07a15d01cf43 100644
--- a/llvm/test/Transforms/InstCombine/load-combine-metadata-dominance.ll
+++ b/llvm/test/Transforms/InstCombine/load-combine-metadata-dominance.ll
@@ -1,4 +1,4 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals --version 2
 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
 
 target datalayout = "e-m:e-p:64:64:64-i64:64-f80:128-n8:16:32:64-S128"
@@ -96,5 +96,57 @@ bb1:
   store i32 0, ptr %b
   ret void
 }
+
+define void @combine_metadata_dominance5(ptr %p) {
+; CHECK-LABEL: define void @combine_metadata_dominance5
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br label [[BB1:%.*]]
+; CHECK:       bb1:
+; CHECK-NEXT:    [[A:%.*]] = load ptr, ptr [[P]], align 8, !align !1
+; CHECK-NEXT:    store i32 0, ptr [[A]], align 4
+; CHECK-NEXT:    ret void
+;
+entry:
+  %a = load ptr, ptr %p, !align !2
+  br label %bb1
+
+bb1:
+  %b = load ptr, ptr %p, !align !3
+  store i32 0, ptr %a
+  store i32 0, ptr %b
+  ret void
+}
+
+define void @combine_metadata_dominance6(ptr %p) {
+; CHECK-LABEL: define void @combine_metadata_dominance6
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br label [[BB1:%.*]]
+; CHECK:       bb1:
+; CHECK-NEXT:    [[A:%.*]] = load ptr, ptr [[P]], align 8, !align !2, !noundef !0
+; CHECK-NEXT:    store i32 0, ptr [[A]], align 8
+; CHECK-NEXT:    ret void
+;
+entry:
+  %a = load ptr, ptr %p, !align !2, !noundef !1
+  br label %bb1
+
+bb1:
+  %b = load ptr, ptr %p, !align !3
+  store i32 0, ptr %a
+  store i32 0, ptr %b
+  ret void
+}
+
 !0 = !{}
 !1 = !{}
+!2 = !{i64 8}
+!3 = !{i64 4}
+;.
+; CHECK: attributes #[[ATTR0:[0-9]+]] = { memory(read) }
+;.
+; CHECK: [[META0:![0-9]+]] = !{}
+; CHECK: [[META1:![0-9]+]] = !{i64 4}
+; CHECK: [[META2:![0-9]+]] = !{i64 8}
+;.


        


More information about the llvm-branch-commits mailing list