[llvm-commits] [llvm] r151003 - in /llvm/trunk: lib/Transforms/IPO/GlobalOpt.cpp test/Transforms/GlobalOpt/invariant.ll
Nick Lewycky
nicholas at mxc.ca
Mon Feb 20 15:32:26 PST 2012
Author: nicholas
Date: Mon Feb 20 17:32:26 2012
New Revision: 151003
URL: http://llvm.org/viewvc/llvm-project?rev=151003&view=rev
Log:
Check for the correct size in the invariant marker.
Modified:
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
llvm/trunk/test/Transforms/GlobalOpt/invariant.ll
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=151003&r1=151002&r2=151003&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Mon Feb 20 17:32:26 2012
@@ -2511,10 +2511,13 @@
if (!II->use_empty())
return false;
ConstantInt *Size = cast<ConstantInt>(II->getArgOperand(0));
- if (Size->isAllOnesValue()) {
- Value *PtrArg = getVal(II->getArgOperand(1));
- Value *Ptr = PtrArg->stripPointerCasts();
- if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Ptr))
+ Value *PtrArg = getVal(II->getArgOperand(1));
+ Value *Ptr = PtrArg->stripPointerCasts();
+ if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Ptr)) {
+ Type *ElemTy = cast<PointerType>(GV->getType())->getElementType();
+ if (!Size->isAllOnesValue() &&
+ Size->getValue().getLimitedValue() >=
+ TD->getTypeStoreSize(ElemTy))
Invariants.insert(GV);
}
// Continue even if we do nothing.
Modified: llvm/trunk/test/Transforms/GlobalOpt/invariant.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/invariant.ll?rev=151003&r1=151002&r2=151003&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/invariant.ll (original)
+++ llvm/trunk/test/Transforms/GlobalOpt/invariant.ll Mon Feb 20 17:32:26 2012
@@ -1,9 +1,12 @@
; RUN: opt -globalopt -S -o - < %s | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
declare {}* @llvm.invariant.start(i64 %size, i8* nocapture %ptr)
define void @test1(i8* %ptr) {
- call {}* @llvm.invariant.start(i64 -1, i8* %ptr)
+ call {}* @llvm.invariant.start(i64 4, i8* %ptr)
ret void
}
@@ -22,12 +25,35 @@
define void @ctor2() {
store i32 -1, i32* @object2
%A = bitcast i32* @object2 to i8*
- %B = call {}* @llvm.invariant.start(i64 -1, i8* %A)
+ %B = call {}* @llvm.invariant.start(i64 4, i8* %A)
%C = bitcast {}* %B to i8*
ret void
}
+
+ at object3 = global i32 0
+; CHECK: @object3 = global i32 -1
+define void @ctor3() {
+ store i32 -1, i32* @object3
+ %A = bitcast i32* @object3 to i8*
+ call {}* @llvm.invariant.start(i64 3, i8* %A)
+ ret void
+}
+
+
+ at object4 = global i32 0
+; CHECK: @object4 = global i32 -1
+define void @ctor4() {
+ store i32 -1, i32* @object4
+ %A = bitcast i32* @object4 to i8*
+ call {}* @llvm.invariant.start(i64 -1, i8* %A)
+ ret void
+}
+
+
@llvm.global_ctors = appending constant
- [2 x { i32, void ()* }]
+ [4 x { i32, void ()* }]
[ { i32, void ()* } { i32 65535, void ()* @ctor1 },
- { i32, void ()* } { i32 65535, void ()* @ctor2 } ]
+ { i32, void ()* } { i32 65535, void ()* @ctor2 },
+ { i32, void ()* } { i32 65535, void ()* @ctor3 },
+ { i32, void ()* } { i32 65535, void ()* @ctor4 } ]
More information about the llvm-commits
mailing list