[PATCH] SROA fix to avoid invalid bitcast generation when converting a load from a double pointer bitcasted with an address space change of the pointee pointee

Michele Scandale michele.scandale at gmail.com
Fri Mar 7 10:27:49 PST 2014


  I tested it at commit 122a970111b8ec66ae330f2c218ae951dddaf75b, and still I have an assertion on "castIsValid": the problem is exactly on pointer of pointer where the bitcast changes the address space of the pointee pointee.

    define void @union_cvt_float2(<2 x float> addrspace(1)* %p) {
     %p.addr = alloca <2 x float> addrspace(1)*, align 8
     store <2 x float> addrspace(1)* %p, <2 x float> addrspace(1)** %p.addr, align 8
     %1 = bitcast <2 x float> addrspace(1)** %p.addr to <2 x float>**
     %2 = load <2 x float>** %1, align 8
     call void @ext_call_float2(<2 x float>* %2)
     ret void
    }

  In this example SROA wants to replace `%2 = load <2 x float>** %1, align 8` with `%2 = bitcast <2 x float> addrspace(1)* %p to <2 x float>*`, but this is an invalid instruction!
  The input IR does the following:
  -  bitcast the address of the stack location associated to the parameter (`<2 x float> addrspace(1)*`) to an address pointing to another type (`<2 x float>*`)
  -  load a `<2 x float>*` from the bitcasted address

  The conservative assumption is that `sizeof(<2 x float> addrspace(1)*) != <2 x float>*`: in this case only the bits in the overlapped region are the same, thus IMHO the right transformation to preserve the semantic is to use ptrtoint+inttoptr using as middle type an integer type that can fully contains the original value.

http://llvm-reviews.chandlerc.com/D3002



More information about the llvm-commits mailing list