[EarlyCSE] Call combineMetadataForCSE() when CSEing loads
authorNikita Popov <npopov@redhat.com>
Mon, 3 Apr 2023 13:51:10 +0000 (15:51 +0200)
committerNikita Popov <npopov@redhat.com>
Mon, 3 Apr 2023 14:10:19 +0000 (16:10 +0200)
We may have to adjust metadata on the replacement load if the
metadata is poison-generating.

llvm/lib/Transforms/Scalar/EarlyCSE.cpp
llvm/test/Transforms/EarlyCSE/flags.ll

index eaec7c0..9c745a2 100644 (file)
@@ -1476,6 +1476,8 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
           LLVM_DEBUG(dbgs() << "Skipping due to debug counter\n");
           continue;
         }
+        if (auto *I = dyn_cast<Instruction>(Op))
+          combineMetadataForCSE(I, &Inst, false);
         if (!Inst.use_empty())
           Inst.replaceAllUsesWith(Op);
         salvageKnowledge(&Inst, &AC);
index 6134c81..57ea086 100644 (file)
@@ -65,7 +65,7 @@ define void @load_both_nonnull(ptr %p) {
 
 define void @load_first_nonnull(ptr %p) {
 ; CHECK-LABEL: @load_first_nonnull(
-; CHECK-NEXT:    [[V1:%.*]] = load ptr, ptr [[P:%.*]], align 8, !nonnull !0
+; CHECK-NEXT:    [[V1:%.*]] = load ptr, ptr [[P:%.*]], align 8
 ; CHECK-NEXT:    call void @use.ptr(ptr [[V1]])
 ; CHECK-NEXT:    call void @use.ptr(ptr [[V1]])
 ; CHECK-NEXT:    ret void