[vmkit-commits] [vmkit] r180293 - Make addition when comparing 2 addresses (for lt, gt, le, ge).
Peter Senna Tschudin
peter.senna at gmail.com
Thu Apr 25 09:52:17 PDT 2013
Author: peter.senna
Date: Thu Apr 25 11:49:39 2013
New Revision: 180293
URL: http://llvm.org/viewvc/llvm-project?rev=180293&view=rev
Log:
Make addition when comparing 2 addresses (for lt, gt, le, ge).
NULL ObjectReference is 0 and Object Address is ObjectReference MINUS header size.
So when MINUS is done, NULL ObjectReference's address is GREATER than 0 (addresses are unsigned).
E.G: if foo is NULL ObjectReference and bar is 0x42 Address, foo.toAddress().GE(bar) return true!
Additionning header's size to addresses when comparing solves the problem.
(cherry picked from commit c11b95ad63a0d0d837cf274c3773a757ffa9144e)
Modified:
vmkit/trunk/mmtk/magic/LowerMagic.cpp
Modified: vmkit/trunk/mmtk/magic/LowerMagic.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/magic/LowerMagic.cpp?rev=180293&r1=180292&r2=180293&view=diff
==============================================================================
--- vmkit/trunk/mmtk/magic/LowerMagic.cpp (original)
+++ vmkit/trunk/mmtk/magic/LowerMagic.cpp Thu Apr 25 11:49:39 2013
@@ -536,6 +536,9 @@ bool LowerMagic::runOnFunction(Function&
Value* Val2 = Call.getArgument(1);
Val1 = new PtrToIntInst(Val1, pointerSizeType, "", CI);
Val2 = new PtrToIntInst(Val2, pointerSizeType, "", CI);
+ Constant* M = ConstantInt::get(pointerSizeType, gcHeader::hiddenHeaderSize());
+ Val1 = BinaryOperator::CreateAdd(Val1, M, "", CI);
+ Val2 = BinaryOperator::CreateAdd(Val2, M, "", CI);
Value* res = new ICmpInst(CI, ICmpInst::ICMP_ULT, Val1, Val2, "");
res = new ZExtInst(res, FCur->getReturnType(), "", CI);
CI->replaceAllUsesWith(res);
@@ -545,6 +548,9 @@ bool LowerMagic::runOnFunction(Function&
Value* Val2 = Call.getArgument(1);
Val1 = new PtrToIntInst(Val1, pointerSizeType, "", CI);
Val2 = new PtrToIntInst(Val2, pointerSizeType, "", CI);
+ Constant* M = ConstantInt::get(pointerSizeType, gcHeader::hiddenHeaderSize());
+ Val1 = BinaryOperator::CreateAdd(Val1, M, "", CI);
+ Val2 = BinaryOperator::CreateAdd(Val2, M, "", CI);
Value* res = new ICmpInst(CI, ICmpInst::ICMP_UGT, Val1, Val2, "");
res = new ZExtInst(res, FCur->getReturnType(), "", CI);
CI->replaceAllUsesWith(res);
@@ -572,6 +578,9 @@ bool LowerMagic::runOnFunction(Function&
Value* Val2 = Call.getArgument(1);
Val1 = new PtrToIntInst(Val1, pointerSizeType, "", CI);
Val2 = new PtrToIntInst(Val2, pointerSizeType, "", CI);
+ Constant* M = ConstantInt::get(pointerSizeType, gcHeader::hiddenHeaderSize());
+ Val1 = BinaryOperator::CreateAdd(Val1, M, "", CI);
+ Val2 = BinaryOperator::CreateAdd(Val2, M, "", CI);
Value* res = new ICmpInst(CI, ICmpInst::ICMP_ULE, Val1, Val2, "");
res = new ZExtInst(res, FCur->getReturnType(), "", CI);
CI->replaceAllUsesWith(res);
@@ -581,6 +590,9 @@ bool LowerMagic::runOnFunction(Function&
Value* Val2 = Call.getArgument(1);
Val1 = new PtrToIntInst(Val1, pointerSizeType, "", CI);
Val2 = new PtrToIntInst(Val2, pointerSizeType, "", CI);
+ Constant* M = ConstantInt::get(pointerSizeType, gcHeader::hiddenHeaderSize());
+ Val1 = BinaryOperator::CreateAdd(Val1, M, "", CI);
+ Val2 = BinaryOperator::CreateAdd(Val2, M, "", CI);
Value* res = new ICmpInst(CI, ICmpInst::ICMP_UGE, Val1, Val2, "");
res = new ZExtInst(res, FCur->getReturnType(), "", CI);
CI->replaceAllUsesWith(res);
More information about the vmkit-commits
mailing list