[PATCH] [IC] Turn non-null MD on pointer loads to range MD on integer loads.
Charles Davis
cdavis5x at gmail.com
Fri Feb 13 12:19:40 PST 2015
Hi chandlerc,
This change fixes the FIXME that you recently added when you committed
(a modified version of) my patch. When `InstCombine` combines a load and
store of an pointer to those of an equivalently-sized integer, it currently
drops any `!nonnull` metadata that might be present. This change replaces
`!nonnull` metadata with `!range !{ 1, -1 }` metadata instead.
(Yes, everything with my Gmail account is OK, now. Thanks for your help!)
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
@@ -335,10 +335,20 @@
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 it's integral, translate it to !range metadata.
+ auto *ITy = dyn_cast<IntegerType>(NewTy);
+ if (!ITy) break;
+ Metadata *Range[] = {
+ ConstantAsMetadata::get(IC.Builder->getIntN(ITy->getBitWidth(), 1)),
+ ConstantAsMetadata::get(IC.Builder->getIntN(ITy->getBitWidth(),
+ ITy->getBitMask()))
+ };
+ NewLoad->setMetadata(LLVMContext::MD_range,
+ MDTuple::get(NewLoad->getContext(), Range));
+ }
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,10 +83,9 @@
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
; CHECK-NOT: !nonnull
; CHECK: store i64 %[[V]], i64*
entry:
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7621.19919.patch
Type: text/x-patch
Size: 1817 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150213/522c6f6e/attachment.bin>
More information about the llvm-commits
mailing list