[llvm-commits] [llvm] r45403 - in /llvm/trunk/lib/Transforms/Scalar: InstructionCombining.cpp SCCP.cpp
Christopher Lamb
christopher.lamb at gmail.com
Wed Jan 2 11:56:02 PST 2008
For embedded devices with special address spaces often 0x0 is a valid
address in those spaces. I knew this was going to be a troublesome
issue as it goes against a basic assumption for single address space
compilation. I know that this assumption is salted away in xforms
scattered throughout the compiler, and I'm resigned to addressing
them as they become evident.
I would appreciate some advice on how to provide target specific
information to analysis and transforms (alias analysis could also
benefit from target specific address space information). Is there an
example where this is already being done?
--
Chris
On Jan 2, 2008, at 12:55 PM, Chris Lattner wrote:
>
> On Dec 28, 2007, at 11:56 PM, Christopher Lamb wrote:
>> URL: http://llvm.org/viewvc/llvm-project?rev=45403&view=rev
>> Log:
>> Disable null pointer folding transforms for non-generic address
>> spaces. This should probably be a target-specific predicate based
>> on address space. That way for targets where this isn't applicable
>> the predicate can be optimized away.
>
> Hi Christopher,
>
> Is this really needed? There are a variety of places in the
> compiler that assume that a null pointer load/store is invalid.
> For example, I think we turn "x = load p; c = p == null" into "x =
> load p; c = false" for example. Is there any other solution to the
> problem you've hit?
>
> -Chris
>
>> Modified:
>> llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
>> llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
>>
>> Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/
>> Scalar/InstructionCombining.cpp?rev=45403&r1=45402&r2=45403&view=diff
>>
>> =====================================================================
>> =========
>> --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
>> (original)
>> +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Sat
>> Dec 29 01:56:53 2007
>> @@ -9338,8 +9338,11 @@
>> return ReplaceInstUsesWith(LI, LIB);
>> }
>>
>> - if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Op))
>> - if (isa<ConstantPointerNull>(GEPI->getOperand(0))) {
>> + if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Op)) {
>> + const Value *GEPI0 = GEPI->getOperand(0);
>> + // TODO: Consider a target hook for valid address spaces for
>> this xform.
>> + if (isa<ConstantPointerNull>(GEPI0) &&
>> + cast<PointerType>(GEPI0->getType())->getAddressSpace() ==
>> 0) {
>> // Insert a new store to null instruction before the load
>> to indicate
>> // that this code is not reachable. We do this instead of
>> inserting
>> // an unreachable instruction directly because we cannot
>> modify the
>> @@ -9348,10 +9351,13 @@
>> Constant::getNullValue(Op->getType()), &LI);
>> return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
>> }
>> + }
>>
>> if (Constant *C = dyn_cast<Constant>(Op)) {
>> // load null/undef -> undef
>> - if ((C->isNullValue() || isa<UndefValue>(C))) {
>> + // TODO: Consider a target hook for valid address spaces for
>> this xform.
>> + if (isa<UndefValue>(C) || (C->isNullValue() &&
>> + cast<PointerType>(Op->getType())->getAddressSpace() == 0)) {
>> // Insert a new store to null instruction before the load
>> to indicate that
>> // this code is not reachable. We do this instead of
>> inserting an
>> // unreachable instruction directly because we cannot
>> modify the CFG.
>>
>> Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/
>> Scalar/SCCP.cpp?rev=45403&r1=45402&r2=45403&view=diff
>>
>> =====================================================================
>> =========
>> --- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Sat Dec 29 01:56:53
>> 2007
>> @@ -1015,7 +1015,9 @@
>> if (PtrVal.isUndefined()) return; // The pointer is not
>> resolved yet!
>> if (PtrVal.isConstant() && !I.isVolatile()) {
>> Value *Ptr = PtrVal.getConstant();
>> - if (isa<ConstantPointerNull>(Ptr)) {
>> + // TODO: Consider a target hook for valid address spaces for
>> this xform.
>> + if (isa<ConstantPointerNull>(Ptr) &&
>> + cast<PointerType>(Ptr->getType())->getAddressSpace() == 0) {
>> // load null -> null
>> markConstant(IV, &I, Constant::getNullValue(I.getType()));
>> return;
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
--
Christopher Lamb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20080102/ff84cf0b/attachment.html>
More information about the llvm-commits
mailing list