Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Correctly handle range metadata when hoisting instructions into if blocks #15

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,10 @@ static bool HoistThenElseCodeToIf(BranchInst *BI) {
if (!I2->use_empty())
I2->replaceAllUsesWith(I1);
I1->intersectOptionalDataWith(I2);
I1->setMetadata(LLVMContext::MD_range,
MDNode::getMostGenericRange(
I1->getMetadata(LLVMContext::MD_range),
I2->getMetadata(LLVMContext::MD_range)));
I2->eraseFromParent();

I1 = BB1_Itr++;
Expand Down
20 changes: 20 additions & 0 deletions test/Transforms/SimplifyCFG/hoist-with-range.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; RUN: opt < %s -simplifycfg -S | FileCheck %s

define void @foo(i1 %c, i8* %p) {
; CHECK: if:
; CHECK-NEXT: load i8* %p, !range !0
; CHECK: !0 = metadata !{i8 0, i8 1, i8 3, i8 5}
if:
br i1 %c, label %then, label %else
then:
%t = load i8* %p, !range !0
br label %out
else:
%e = load i8* %p, !range !1
br label %out
out:
ret void
}

!0 = metadata !{ i8 0, i8 1 }
!1 = metadata !{ i8 3, i8 5 }