This is an archive of the discontinued LLVM Phabricator instance.

Fix constant folding of addrspacecast
ClosedPublic

Authored by arsenm on May 10 2016, 5:20 PM.

Details

Reviewers
majnemer

Diff Detail

Event Timeline

arsenm updated this revision to Diff 56841.May 10 2016, 5:20 PM
arsenm retitled this revision from to Fix constant folding of addrspacecast.
arsenm updated this object.
arsenm added a subscriber: llvm-commits.
majnemer added inline comments.May 20 2016, 2:34 PM
lib/Analysis/ConstantFolding.cpp
1232–1246 ↗(On Diff #56841)

This is suspicious to me. It implies that performing a ConstantExpr::getCast(Instruction::AddrSpaceCast) on an IntToPtr does the wrong thing and suggests to me that the bug lies elsewhere.

arsenm updated this revision to Diff 57999.May 20 2016, 3:09 PM

Add test that shows ConstantExpr::getAddrSpaceCast does the right thing

majnemer edited edge metadata.May 20 2016, 3:56 PM

Er, I'm still very confused here. Let's take your example @constant_fold_inttoptr.

trunk turns this into:

define void @constant_fold_inttoptr() {
  store i32 7, i32 addrspace(4)* addrspacecast (i32 addrspace(3)* inttoptr (i32 -1 to i32 addrspace(3)*) to i32 addrspace(4)*)
  ret void
}

I'm not seeing an argument as to why this is not desirable. The target should still have all the information it needs, the only difference I see is that contains an additional ConstantExpr instead of an additional Instruction.

Er, I'm still very confused here. Let's take your example @constant_fold_inttoptr.

trunk turns this into:

define void @constant_fold_inttoptr() {
  store i32 7, i32 addrspace(4)* addrspacecast (i32 addrspace(3)* inttoptr (i32 -1 to i32 addrspace(3)*) to i32 addrspace(4)*)
  ret void
}

I'm not seeing an argument as to why this is not desirable. The target should still have all the information it needs, the only difference I see is that contains an additional ConstantExpr instead of an additional Instruction.

The constant value for a pointer in one address space may not match the value in another address space, so constant folding it to the same constant is incorrect

arsenm updated this revision to Diff 58019.May 20 2016, 5:06 PM
arsenm edited edge metadata.

Only need to handle null

majnemer accepted this revision.May 20 2016, 5:08 PM
majnemer edited edge metadata.

LGTM

This revision is now accepted and ready to land.May 20 2016, 5:08 PM
arsenm closed this revision.May 20 2016, 5:20 PM

r270293