[PATCH] D25215: [InstCombine] Transform !range metadata to !nonnull when combining loads
Ariel Ben-Yehuda via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 3 16:38:43 PDT 2016
arielb1 created this revision.
arielb1 added a reviewer: chandlerc.
arielb1 added a subscriber: llvm-commits.
arielb1 set the repository for this revision to rL LLVM.
When combining an integer load with !range metadata that does not include 0 to a pointer load, make sure emit !nonnull metadata on the newly-created pointer load. This prevents the !nonnull metadata from being dropped during a ptrtoint/inttoptr pair.
This fixes PR30597
Repository:
rL LLVM
https://reviews.llvm.org/D25215
Files:
lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
test/Transforms/InstCombine/PR30597.ll
Index: test/Transforms/InstCombine/PR30597.ll
===================================================================
--- /dev/null
+++ test/Transforms/InstCombine/PR30597.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -instcombine -simplifycfg -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK-LABEL: @dot_ref_s
+; CHECK-NEXT: ret 42
+
+; Function Attrs: readonly uwtable
+define i32 @dot_ref_s(i32** noalias nocapture readonly dereferenceable(8)) {
+entry-block:
+ %loadedptr = load i32*, i32** %0, align 8, !nonnull !0
+ %ptrtoint = ptrtoint i32* %loadedptr to i64
+ %inttoptr = inttoptr i64 %ptrtoint to i32*
+ %switchtmp = icmp eq i32* %inttoptr, null
+ br i1 %switchtmp, label %bb6, label %bb7
+
+bb6:
+ ret i32 0
+
+bb7:
+ ret i32 42
+}
+
+!0 = !{}
Index: lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -380,8 +380,16 @@
break;
case LLVMContext::MD_range:
// FIXME: It would be nice to propagate this in some way, but the type
- // conversions make it hard. If the new type is a pointer, we could
- // translate it to !nonnull metadata.
+ // conversions make it hard.
+
+ // If it's a pointer now and the range does not contain 0, make it !nonnull.
+ if (NewTy->isPointerTy() && N->getNumOperands() == 2) {
+ unsigned int BitWidth = IC.getDataLayout().getTypeSizeInBits(NewTy);
+ if (!getConstantRangeFromMetadata(*N).contains(APInt(BitWidth, 0))) {
+ MDNode *NN = MDNode::get(LI.getContext(), None);
+ NewLoad->setMetadata(LLVMContext::MD_nonnull, NN);
+ }
+ }
break;
}
}
@@ -1279,7 +1287,7 @@
bool InstCombiner::SimplifyStoreAtEndOfBlock(StoreInst &SI) {
assert(SI.isUnordered() &&
"this code has not been auditted for volatile or ordered store case");
-
+
BasicBlock *StoreBB = SI.getParent();
// Check to see if the successor block has exactly two incoming edges. If
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25215.73371.patch
Type: text/x-patch
Size: 2177 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161003/c8709f48/attachment.bin>
More information about the llvm-commits
mailing list