<html><body><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10pt"><div style="RIGHT: auto">Hi All,</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">I have been having this issue, when I am enable Instruction Combining pass, for an application.</div>
<div style="RIGHT: auto">I have read similar post ealier,</div>
<div style="RIGHT: auto"><A style="RIGHT: auto" href="http://old.nabble.com/Instruction-Combining-Pass-*Breaking*-Struct-Reads--td24253572.html"><FONT style="RIGHT: auto" color=#800080>http://old.nabble.com/Instruction-Combining-Pass-*Breaking*-Struct-Reads--td24253572.html</FONT></A> </div>
<div style="RIGHT: auto">With reference to the above case, my target data layout is defined as:</div>
<div style="RIGHT: auto">DataLayout("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-a:32:32")</div>
<div style="RIGHT: auto">Thus I don't see problem mentioned in the above reference.</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">In the function "visitGetElementPtrInst" has a piece of code for handling bitcasts, </div>
<div style="RIGHT: auto">   /// See if we can simplify:<BR>  ///   X = bitcast A* to B*<BR>  ///   Y = gep X, <...constant indices...><BR>which when commented, does not give me problem.</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">The application uses a buffer.  This buffer is assigned to struct such as "FRAME_DATA", instead of allocating space for struct and then using it (I think, this is some kind of good usage of memory). </div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">Detailng further in the application,</div>
<div style="RIGHT: auto">The used buffer is a 16 bit pointer, declared as: </div>
<div style="RIGHT: auto">#define SAMPLE 1024</div>
<div style="RIGHT: auto">>> Word16 Data[4*SAMPLE];                  /*!< Output buffer */<BR></div>
<div style="RIGHT: auto">Elements of this buffer are initialized to 0 in main function./* initialize time data buffer */<BR>        for (i=0; i < 4*SAMPLE; i++){<BR>                Data[i] = 0;<BR>        }<BR></div>
<div style="RIGHT: auto">This filled buffer is then passed to various functions, on it's journey handling data at various instance of time about frames.</div>
<div style="RIGHT: auto">These functions use this buffer, by assiging to appropriate struct pointers (memory reusing probably). </div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">   frameDLt  = (FRAME_DATA*) &Data[MAX_SIZE];<BR>   frameDRt  = (FRAME_DATA*) &Data[3*MAX_SIZE];<BR></div>
<div style="RIGHT: auto">Where frameDLt and frameDRt are struct pointers to </div>
<div style="RIGHT: auto">"FRAME_DATA *frameDLt;" and "SBR_FRAME_DATA *frameDRt;"</div>
<div> </div>
<div style="RIGHT: auto">The struct is defined as:</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto"> %struct._FRAME_DATA = type { i16, %struct._FRAME_INFO, [5 x i16], [2 x i16], [5 x i32], i32, i16, [48 x i32], i16, [240 x i16], [10 x i16] }<BR> %struct._FRAME_INFO = type { i16, i16, [6 x i16], [5 x i16], i16, i16, [3 x i16] } </div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">The code generated, when trying to access "coupling, a member 16 bit variable of struct", "without instruction combining" is:</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">%coupling = <STRONG>getelementptr</STRONG> inbounds <STRONG style="RIGHT: auto">%struct._FRAME_DATA* %2, i32 0, i32 5</STRONG>, !dbg !575<BR>  store i32 0, i32* %coupling, align 4, !dbg !575</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">And the code generated "with instruction combining" is:</div>
<div style="RIGHT: auto">%coupling = <STRONG style="RIGHT: auto">getelementptr</STRONG> inbounds i16* <STRONG style="RIGHT: auto">%timeData, i32</STRONG> <STRONG>1060</STRONG>, !dbg !575<BR>  %24 = bitcast i16* %coupling to i32*, !dbg !575<BR>  store i32 0, i32* %24, align 4, !dbg !575</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">The FRAME_DATA, is defined as:</div>
<div style="RIGHT: auto">typedef struct _FRAME_DATA<BR>{<BR>  Word16 nScaleFactors;                    /*!< total number of scalefactors in frame */</div>
<div style="RIGHT: auto">  FRAME_INFO frameInfo;                 /*!< time grid for current frame */<BR>  Word16 domain_vec[MAX_ENVELOPES];  /*!< Bitfield containing direction of delta-coding for each envelope */<BR>  Word16 domain_vec_noise[MAX_NOISE_ENVELOPES]; /*!< Same as above, but for noise envelopes */</div>
<div style="RIGHT: auto">  INVF_MODE sbr_invf_mode[MAX_INVF_BANDS]; /*!< Strength of filtering in transposer */<BR>  COUPLING_MODE <STRONG style="RIGHT: auto">coupling</STRONG>;               /*!< Stereo-mode */ <BR>  Word16 ampResolutionCurrentFrame;        /*!< Amplitude resolution of envelope values (0: 1.5dB, 1: 3dB) */</div>
<div style="RIGHT: auto">  Flag addHarmonics[MAX_FREQ_COEFFS];   /*!< Flags for synthetic sine addition */<BR>  Word16 maxQmfSubbandAac;       /*!< Solves the 'undefined x-over problem' for the enhancement */</div>
<div style="RIGHT: auto">  Word16 iEnvelope[MAX_NUM_ENVELOPE_VALUES];       /*!< Envelope data */<BR>  Word16 sbrNoiseFloorLevel[MAX_NUM_NOISE_VALUES]; /*!< Noise envelope data */<BR>}<BR>FRAME_DATA;</div>
<div style="RIGHT: auto">COUPLING_MODE is a enum. <BR style="RIGHT: auto"></div>
<div style="RIGHT: auto">the element ptr address calculated by GEP is different in above cases:</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">1. without instruction combining</div>
<div style="RIGHT: auto"><STRONG style="RIGHT: auto">coupling</STRONG> member variable, is at:</div>
<div style="RIGHT: auto">  <STRONG style="RIGHT: auto">%struct._FRAME_DATA* %2, i32 0, i32 5</STRONG></div>
<div style="RIGHT: auto"><STRONG style="RIGHT: auto"></STRONG> </div>
<div style="RIGHT: auto">i.e. at 5 offset in FRAME_DATA i.e. the 6th element, i.e. <STRONG style="RIGHT: auto">coupling </STRONG>member variable.</div>
<div style="RIGHT: auto">Why it is "i32 5" is? If we see this structure has some elements of size i32, so as per C guidelines, other elements will be padded to i32.</div>
<div style="RIGHT: auto">In terms of i16, the <VAR id=yui-ie-cursor></VAR>offset should have been, </div>
<div style="RIGHT: auto">i16, i16, i16, [6 x i16], [5 x i16], i16, i16, [3 x i16], [5x i16], [2 x i16], [5 x i32], i32 ,....</div>
<div style="RIGHT: auto">31 words = 124 bytes.(considering it is aligned to i32)</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">2. with instruction combining<BR>coupling is at:</div>
<div style="RIGHT: auto">i16* <STRONG>%timeData, i32</STRONG> <STRONG style="RIGHT: auto">1060</STRONG></div>
<div style="RIGHT: auto">i.e. 1060 bytes  offset. </div>
<div>This is no way close to what is being referred by "without instruction combining".</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">I felt, the problem with this is the way llvm instruction combining handles generation of offset for a such a situation.</div>
<div style="RIGHT: auto">As I am not sure, I wanted to know more about this. </div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">Regards,</div>
<div style="RIGHT: auto">Pankaj</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto"> </div></div></body></html>