I see instcombine doing something I'm not sure is right. Incoming, I have this: %r29 = ptrtoint [71 x i64]* %"t$3" to i64 ; <i64> [#uses=1] %r30 = inttoptr i64 %r29 to i64* ; <i64*> [#uses=1] store i64 72057594037927936, i64* %r30, align 8 Outgoing, I have this: %r30 = getelementptr [71 x i64]* %"t$3", i32 0, i32 0 ; <i64*> [#uses=1] store i64 72057594037927936, i64* %r30, align 16 I believe the alignment on the outgoing store is wrong, but my question concerns the optimization of the ptrtoint / intoptr to a gep. Is this optimization allowed to pun the pointer type like this or should there be a bitcast to i64* in there somewhere? -Dave
On Jul 16, 2008, at 1:32 PM, David Greene wrote:> I see instcombine doing something I'm not sure is right. > > Incoming, I have this: > > %r29 = ptrtoint [71 x i64]* %"t$3" to i64 ; <i64> [#uses=1] > %r30 = inttoptr i64 %r29 to i64* ; <i64*> [#uses=1] > store i64 72057594037927936, i64* %r30, align 8 > > Outgoing, I have this: > > %r30 = getelementptr [71 x i64]* %"t$3", i32 0, i32 0 ; <i64*> > [#uses=1] > store i64 72057594037927936, i64* %r30, align 16 > > I believe the alignment on the outgoing store is wrong, but my > question > concerns the optimization of the ptrtoint / intoptr to a gep. Is this > optimization allowed to pun the pointer type like this or should > there be > a bitcast to i64* in there somewhere?With what you've shown, the transformation is valid. instcombine will increase the alignment when it knows it is safe. Is %"t$3" derived from something provably 16-byte aligned? -Chris
On Jul 16, 2008, at 1:32 PM, David Greene wrote:> I see instcombine doing something I'm not sure is right. > > Incoming, I have this: > > %r29 = ptrtoint [71 x i64]* %"t$3" to i64 ; <i64> [#uses=1] > %r30 = inttoptr i64 %r29 to i64* ; <i64*> [#uses=1] > store i64 72057594037927936, i64* %r30, align 8 > > Outgoing, I have this: > > %r30 = getelementptr [71 x i64]* %"t$3", i32 0, i32 0 ; <i64*> > [#uses=1] > store i64 72057594037927936, i64* %r30, align 16 > > I believe the alignment on the outgoing store is wrong, but my > question > concerns the optimization of the ptrtoint / intoptr to a gep. Is this > optimization allowed to pun the pointer type like this or should > there be > a bitcast to i64* in there somewhere?Implicit punning of pointer types in registers is not permitted. The above getelementptr isn't doing that though. The first index of a GEP is the one that just adds to the pointer value and doesn't change the type. The second index goes into the pointee type -- the array -- so the result is i64*. Dan
Maybe Matching Threads
- [LLVMdev] Proposal: New IR instruction for casting between address spaces
- [LLVMdev] Proposal: New IR instruction for casting between address spaces
- [LLVMdev] Proposal: New IR instruction for casting between address spaces
- [LLVMdev] Proposal: New IR instruction for casting between address spaces
- [LLVMdev] Proposal: New IR instruction for casting between address spaces