[Local] Add MD_fpmath to combineMetadataForCSE()
authorNikita Popov <npopov@redhat.com>
Mon, 3 Apr 2023 13:26:51 +0000 (15:26 +0200)
committerNikita Popov <npopov@redhat.com>
Mon, 3 Apr 2023 13:27:59 +0000 (15:27 +0200)
This was present in patchReplacementInstruction() but not
combineMetadataForCSE(). combineMetadata() already knows how to
merge these properly.

llvm/lib/Transforms/Utils/Local.cpp
llvm/test/Transforms/SimplifyCFG/hoist-with-metadata.ll

index 3fb0d0c..7a43ee0 100644 (file)
@@ -2729,15 +2729,21 @@ void llvm::combineMetadata(Instruction *K, const Instruction *J,
 
 void llvm::combineMetadataForCSE(Instruction *K, const Instruction *J,
                                  bool KDominatesJ) {
-  unsigned KnownIDs[] = {
-      LLVMContext::MD_tbaa,            LLVMContext::MD_alias_scope,
-      LLVMContext::MD_noalias,         LLVMContext::MD_range,
-      LLVMContext::MD_invariant_load,  LLVMContext::MD_nonnull,
-      LLVMContext::MD_invariant_group, LLVMContext::MD_align,
-      LLVMContext::MD_dereferenceable,
-      LLVMContext::MD_dereferenceable_or_null,
-      LLVMContext::MD_access_group,    LLVMContext::MD_preserve_access_index,
-      LLVMContext::MD_nontemporal,     LLVMContext::MD_noundef};
+  unsigned KnownIDs[] = {LLVMContext::MD_tbaa,
+                         LLVMContext::MD_alias_scope,
+                         LLVMContext::MD_noalias,
+                         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_access_group,
+                         LLVMContext::MD_preserve_access_index,
+                         LLVMContext::MD_nontemporal,
+                         LLVMContext::MD_noundef};
   combineMetadata(K, J, KnownIDs, KDominatesJ);
 }
 
index 72f9f5b..ae8fd82 100644 (file)
@@ -119,10 +119,29 @@ join:
   ret ptr %phi
 }
 
+define void @hoist_fpmath(i1 %c, double %x) {
+; CHECK-LABEL: @hoist_fpmath(
+; CHECK-NEXT:  if:
+; CHECK-NEXT:    [[T:%.*]] = fadd double [[X:%.*]], 1.000000e+00, !fpmath !2
+; CHECK-NEXT:    ret void
+;
+if:
+  br i1 %c, label %then, label %else
+then:
+  %t = fadd double %x, 1.0, !fpmath !{ float 2.5 }
+  br label %out
+else:
+  %e = fadd double %x, 1.0, !fpmath !{ float 5.0 }
+  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]+]] = !{}
+; CHECK: [[META2:![0-9]+]] = !{float 2.500000e+00}
 ;.