diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 6de602e4c3e4..9d0f17a72b11 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -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++; diff --git a/test/Transforms/SimplifyCFG/hoist-with-range.ll b/test/Transforms/SimplifyCFG/hoist-with-range.ll new file mode 100644 index 000000000000..362aa9a42d1f --- /dev/null +++ b/test/Transforms/SimplifyCFG/hoist-with-range.ll @@ -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 }