[PATCH] [IC] Turn non-null MD on pointer loads to range MD on integer loads.
Charles Davis
cdavis5x at gmail.com
Fri Feb 20 12:15:33 PST 2015
Incorporate @reames' suggested changes.
http://reviews.llvm.org/D7621
Files:
lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
test/Transforms/InstCombine/loadstore-metadata.ll
Index: lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -17,6 +17,7 @@
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/MDBuilder.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
using namespace llvm;
@@ -335,10 +336,16 @@
break;
case LLVMContext::MD_nonnull:
- // FIXME: We should translate this into range metadata for integer types
- // and vice versa.
if (NewTy->isPointerTy())
NewLoad->setMetadata(ID, N);
+ else if (NewTy->isIntegerTy()) {
+ // If it's integral, translate it to !range metadata.
+ const auto *ITy = cast<IntegerType>(NewTy);
+ NewLoad->setMetadata(LLVMContext::MD_range,
+ MDBuilder(NewLoad->getContext())
+ .createRange(APInt(ITy->getBitWidth(), 1),
+ ITy->getMask()));
+ }
break;
case LLVMContext::MD_range:
Index: test/Transforms/InstCombine/loadstore-metadata.ll
===================================================================
--- test/Transforms/InstCombine/loadstore-metadata.ll
+++ test/Transforms/InstCombine/loadstore-metadata.ll
@@ -83,20 +83,19 @@
define void @test_load_cast_combine_nonnull(float** %ptr) {
; We can't preserve nonnull metadata when converting a load of a pointer to
; a load of an integer.
-; FIXME: We should really transform this into range metadata and vice versa.
;
; CHECK-LABEL: @test_load_cast_combine_nonnull(
-; CHECK: %[[V:.*]] = load i64* %{{.*}}
+; CHECK: %[[V:.*]] = load i64* %{{.*}}, !range ![[MD:[0-9]+]]
; CHECK-NOT: !nonnull
; CHECK: store i64 %[[V]], i64*
entry:
%p = load float** %ptr, !nonnull !3
%gep = getelementptr float** %ptr, i32 42
store float* %p, float** %gep
-
ret void
}
+; CHECK: ![[MD]] = !{i64 1, i64 -1}
!0 = !{ !1, !1, i64 0 }
!1 = !{ !1 }
!2 = !{ !2, !1 }
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7621.20424.patch
Type: text/x-patch
Size: 2188 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150220/04eb2a9c/attachment.bin>
More information about the llvm-commits
mailing list