LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 29163 - SimplifyCFG: FoldTwoEntryPHINode does not remove metadata.
Summary: SimplifyCFG: FoldTwoEntryPHINode does not remove metadata.
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Transformation Utilities (show other bugs)
Version: 3.9
Hardware: PC Linux
: P normal
Assignee: David Majnemer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-28 05:38 PDT by edy.burt
Modified: 2016-08-29 12:14 PDT (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description edy.burt 2016-08-28 05:38:28 PDT
In this example, SimplifyCFG::FoldTwoEntryPHINode will make the load unconditional, without removing the !range annotation (which would then kill a null check, in the original testcase):

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@GV = external constant i64

define i64 @test(i1 %cond) {
entry:
  br i1 %cond, label %if, label %then

then:
  %pti = ptrtoint i64* @GV to i64
  br label %join

if:
  %load = load i64, i64* @GV, align 8, !range !0
  br label %join

join:
  %phi = phi i64 [ %pti, %then ], [ %load, %if ]
  ret i64 %phi
}

!0 = !{i64 1, i64 0}

; -----------------------
; After opt -simplifycfg:
define i64 @test(i1 %cond) {
entry:
  %pti = ptrtoint i64* @GV to i64
  %load = load i64, i64* @GV, align 8, !range !0
  %phi = select i1 %cond, i64 %load, i64 %pti
  ret i64 %phi
}
Comment 1 David Majnemer 2016-08-28 21:51:28 PDT
this patch seems to fix it:
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index d11f4e8..59f416e 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2110,14 +2110,20 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
 
   // Move all 'aggressive' instructions, which are defined in the
   // conditional parts of the if's up to the dominating block.
-  if (IfBlock1)
+  if (IfBlock1) {
+    for (auto &I : *IfBlock1)
+      I.dropUnknownNonDebugMetadata();
     DomBlock->getInstList().splice(InsertPt->getIterator(),
                                    IfBlock1->getInstList(), IfBlock1->begin(),
                                    IfBlock1->getTerminator()->getIterator());
-  if (IfBlock2)
+  }
+  if (IfBlock2) {
+    for (auto &I : *IfBlock2)
+      I.dropUnknownNonDebugMetadata();
     DomBlock->getInstList().splice(InsertPt->getIterator(),
                                    IfBlock2->getInstList(), IfBlock2->begin(),
                                    IfBlock2->getTerminator()->getIterator());
+  }
 
   while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {
     // Change the PHI node into a select instruction.
Comment 2 David Majnemer 2016-08-29 12:14:30 PDT
Fixed in r279980.