<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Tim,<div class=""><br class=""><div class="">I agree this should be “solved” in LLVM</div><div class=""><br class=""></div><div class="">Just as a matter of information, this is the test source code and the generated assembly for my target architecture (more comments below):</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class="">struct<span style="color: #000000" class=""> AA</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  <span style="color: #ba2da2" class="">char</span> n;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  <span style="color: #ba2da2" class="">char</span> m;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  <span style="color: #ba2da2" class="">char</span> j;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">};</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class="">struct<span style="color: #000000" class=""> BB</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  <span style="color: #ba2da2" class="">char</span> n;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  <span style="color: #ba2da2" class="">char</span> m;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  <span style="color: #ba2da2" class="">char</span> j;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  <span style="color: #ba2da2" class="">char</span> k;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">};</div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="color: #ba2da2" class="">extern</span> <span style="color: #ba2da2" class="">void</span> convertA( <span style="color: #ba2da2" class="">struct</span> AA *a);</div><div style="margin: 0px; line-height: normal;" class=""><span style="color: #ba2da2" class="">extern</span> <span style="color: #ba2da2" class="">void</span> convertB( <span style="color: #ba2da2" class="">struct</span> BB *b);</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="color: #ba2da2" class="">void</span> callConvertA()</div><div style="margin: 0px; line-height: normal;" class="">{</div><div style="margin: 0px; line-height: normal;" class="">  <span style="color: #ba2da2" class="">struct</span> AA a = {<span style="color: #272ad8" class="">3</span>, <span style="color: #272ad8" class="">4</span>};</div><div style="margin: 0px; line-height: normal;" class="">  convertA( &a );</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="color: #ba2da2" class="">void</span> callConvertB()</div><div style="margin: 0px; line-height: normal;" class="">{</div><div style="margin: 0px; line-height: normal;" class="">  <span style="color: #ba2da2" class="">struct</span> BB b = {<span style="color: #272ad8" class="">3</span>, <span style="color: #272ad8" class="">4</span>};</div><div style="margin: 0px; line-height: normal;" class="">  convertB( &b );</div><div style="margin: 0px; line-height: normal;" class="">}</div></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">callConvertA:                           ; @callConvertA</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">; %bb<span style="color: #272ad8" class="">.0</span>:                                ; %entry</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">       </span>sub<span class="Apple-tab-span" style="white-space:pre"> </span>SP, <span style="color: #008400" class="">#4, SP</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">   </span>mov<span class="Apple-tab-span" style="white-space:pre"> </span>&.LcallConvertA.a, r0</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>ld.sb<span class="Apple-tab-span" style="white-space:pre">       </span>[r0, <span style="color: #008400" class="">#2], r1</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>st.b<span class="Apple-tab-span" style="white-space:pre">        </span>r1, [SP, <span style="color: #008400" class="">#2]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>ld.sb<span class="Apple-tab-span" style="white-space:pre">       </span>[r0, <span style="color: #008400" class="">#0], r1</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>zext<span class="Apple-tab-span" style="white-space:pre">        </span>r1, r1</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">    </span>ld.sb<span class="Apple-tab-span" style="white-space:pre">       </span>[r0, <span style="color: #008400" class="">#1], r0</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>zext<span class="Apple-tab-span" style="white-space:pre">        </span>r0, r0</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">    </span>bswap<span class="Apple-tab-span" style="white-space:pre">       </span>r0, r0</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">    </span>or<span class="Apple-tab-span" style="white-space:pre">  </span>r0, r1, r0</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>st.w<span class="Apple-tab-span" style="white-space:pre">        </span>r0, [SP, <span style="color: #008400" class="">#0]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>mov<span class="Apple-tab-span" style="white-space:pre"> </span>SP, r0</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">    </span>call<span class="Apple-tab-span" style="white-space:pre">        </span>&convertA</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">     </span>add<span class="Apple-tab-span" style="white-space:pre"> </span>SP, <span style="color: #008400" class="">#4, SP</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">   </span>ret</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">.Lfunc_end0:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>.size<span class="Apple-tab-span" style="white-space:pre">       </span>callConvertA, .Lfunc_end0-callConvertA</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">                                        ; -- End function</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">     </span>.globl<span class="Apple-tab-span" style="white-space:pre">      </span>callConvertB            ; -- Begin function callConvertB</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">    </span>.p2align<span class="Apple-tab-span" style="white-space:pre">    </span><span style="color: #272ad8" class="">1</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">    </span>.type<span class="Apple-tab-span" style="white-space:pre">       </span>callConvertB,@function</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">callConvertB:                           ; @callConvertB</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">; %bb<span style="color: #272ad8" class="">.0</span>:                                ; %entry</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">   </span>sub<span class="Apple-tab-span" style="white-space:pre"> </span>SP, <span style="color: #008400" class="">#4, SP</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">    </span>mov<span class="Apple-tab-span" style="white-space:pre"> </span></span>#0, r0</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">       </span>st.w<span class="Apple-tab-span" style="white-space:pre">        </span>r0, [SP, <span style="color: #008400" class="">#2]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">  </span>mov<span class="Apple-tab-span" style="white-space:pre"> </span></span>#1027, r0</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">    </span>st.w<span class="Apple-tab-span" style="white-space:pre">        </span>r0, [SP, <span style="color: #008400" class="">#0]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>mov<span class="Apple-tab-span" style="white-space:pre"> </span>SP, r0</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">    </span>call<span class="Apple-tab-span" style="white-space:pre">        </span>&convertB</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">     </span>add<span class="Apple-tab-span" style="white-space:pre"> </span>SP, <span style="color: #008400" class="">#4, SP</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">   </span>ret</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">.Lfunc_end1:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>.size<span class="Apple-tab-span" style="white-space:pre">       </span>callConvertB, .Lfunc_end1-callConvertB</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">                                        ; -- End function</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">     </span>.type<span class="Apple-tab-span" style="white-space:pre">       </span>.LcallConvertA.a,@object ; @callConvertA.a</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>.section<span class="Apple-tab-span" style="white-space:pre">    </span>.rodata,<span style="color: #d12f1b" class="">"a"</span>,@progbits</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">.LcallConvertA.a:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">   </span>.byte<span class="Apple-tab-span" style="white-space:pre">       </span><span style="color: #272ad8" class="">3</span>                       ; <span style="color: #272ad8" class="">0x3</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">    </span>.byte<span class="Apple-tab-span" style="white-space:pre">       </span><span style="color: #272ad8" class="">4</span>                       ; <span style="color: #272ad8" class="">0x4</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">    </span>.byte<span class="Apple-tab-span" style="white-space:pre">       </span><span style="color: #272ad8" class="">0</span>                       ; <span style="color: #272ad8" class="">0x0</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">    </span>.size<span class="Apple-tab-span" style="white-space:pre">       </span>.LcallConvertA.a, <span style="color: #272ad8" class="">3</span></div></div><div class=""><span style="color: #272ad8" class=""><br class=""></span></div><div class="">Please note that for this architecture the destination operand is on the RIGHT HAND SIDE, this is important to know to read the assembly correctly.</div><div class=""><br class=""></div><div class="">“ld.sb" are signextend 8 bit loads</div><div class="">“st,b” are 8 bit trunc stores</div><div class="">“ld.w” are 16 bit word loads</div><div class="">“st.w” are 16 bit word stores</div><div class=""><br class=""></div><div class="">The generated code is functionally correct, but:</div><div class=""><br class=""></div><div class="">- For callConvertA  i8, i8, i8 loads + i8, i16 stores are generated. To get the value of two i8, i8 loads into a i16 store the “zext”+”bswap” (equivalent to shift) + “or” trick is performed</div><div class="">- For callConvertB i16, i16 loads + i16, i16 stores are generated.</div><div class=""><br class=""></div><div class="">The desired behaviour would be to have i16, i8 loads + i16, i8 stores for the callConvertA.</div><div class=""><br class=""></div><div class="">The only difference that I can spot by debugging the LLVM source code is that <span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">getMemcpyLoadsAndStores</span> is called with align = 1 for callConvertA, but it is NOT called for callConvertB.</div><div class=""><br class=""></div><div class="">The Clang generated IR is this:</div><div class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">; ModuleID = 'add.c'</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">source_filename = "add.c"</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">target datalayout = "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16"</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">target triple = "cpu74"</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">%struct.AA = type { i8, i8, i8 }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">%struct.BB = type { i8, i8, i8, i8 }</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">@callConvertA.a = private unnamed_addr constant %struct.AA { i8 3, i8 4, i8 0 }, align 1</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">; Function Attrs: minsize nounwind optsize</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">define dso_local void @callConvertA() local_unnamed_addr #0 {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">entry:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  %a = alloca %struct.AA, align 1</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  %0 = getelementptr inbounds %struct.AA, %struct.AA* %a, i16 0, i32 0</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  call void @llvm.lifetime.start.p0i8(i64 3, i8* nonnull %0) #3</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  call void @llvm.memcpy.p0i8.p0i8.i16(i8* nonnull align 1 %0, i8* align 1 getelementptr inbounds (%struct.AA, %struct.AA* @callConvertA.a, i16 0, i32 0), i16 3, i1 false)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  call void @convertA(%struct.AA* nonnull %a) #4</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  call void @llvm.lifetime.end.p0i8(i64 3, i8* nonnull %0) #3</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  ret void</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">; Function Attrs: argmemonly nounwind</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">; Function Attrs: argmemonly nounwind</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">declare void @llvm.memcpy.p0i8.p0i8.i16(i8* nocapture writeonly, i8* nocapture readonly, i16, i1) #1</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">; Function Attrs: minsize optsize</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">declare dso_local void @convertA(%struct.AA*) local_unnamed_addr #2</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">; Function Attrs: argmemonly nounwind</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">; Function Attrs: minsize nounwind optsize</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">define dso_local void @callConvertB() local_unnamed_addr #0 {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">entry:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  %b = alloca i32, align 2</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  %tmpcast = bitcast i32* %b to %struct.BB*</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  %0 = bitcast i32* %b to i8*</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %0) #3</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  store i32 1027, i32* %b, align 2</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  call void @convertB(%struct.BB* nonnull %tmpcast) #4</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %0) #3</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">  ret void</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">; Function Attrs: minsize optsize</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">declare dso_local void @convertB(%struct.BB*) local_unnamed_addr #2</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">attributes #0 = { minsize nounwind optsize "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">attributes #1 = { argmemonly nounwind }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">attributes #2 = { minsize optsize "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">attributes #3 = { nounwind }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">attributes #4 = { minsize nounwind optsize }</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">!llvm.module.flags = !{!0}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">!llvm.ident = !{!1}</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">!0 = !{i32 1, !"wchar_size", i32 2}</div><div class=""><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">!1 = !{!"clang version 7.0.1 (tags/RELEASE_701/final)"}</span>   </div><div class=""><div class=""><br class="webkit-block-placeholder"></div><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">John<br class=""><br class="">Tel: 620 28 45 13</div></div></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On 13 May 2019, at 20:09, Tim Northover <<a href="mailto:t.p.northover@gmail.com" class="">t.p.northover@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hi Joan,<br class=""><br class="">On Mon, 13 May 2019 at 18:01, Joan Lluch <<a href="mailto:joan.lluch@icloud.com" class="">joan.lluch@icloud.com</a>> wrote:<br class=""><blockquote type="cite" class="">After looking at it a bit further, I think this is a Clang thing.  Clang issues “align 2” if the struct has at least one int (2 bytes), but also if the entire struct size is multiple of 2. For example a struct with 4 char members. In these cases the LLVM backend correctly creates word sized load/stores (2 bytes).<br class=""></blockquote><br class="">I'm slightly surprised that it happens based purely on size, but<br class="">either way LLVM should be able to cope.<br class=""><br class=""><blockquote type="cite" class="">The LLVM backend just follows what’s dictated by Clang regarding alignment and thus it creates 2 byte or 1 byte load/stores instructions accordingly. I have not found a way to override this in LLVM. Any suggestions are appreciated.<br class=""></blockquote><br class="">That sounds right, but I don't think it explains the shifts you<br class="">described before. It should work out a lot better than what you're<br class="">seeing. Specifically, a 3 byte struct (for example) ought to either<br class="">lower to:<br class=""><br class="">    load i16, load i8 + stores if your target can do misaligned i16 operations.<br class=""><br class="">or<br class=""><br class="">    load i8, load i8, load i8 + stores if not.<br class=""><br class="">Neither of those involve shifting operations. I'd suggest breaking<br class="">just after getMemcpyLoadsAndStores and using SelectionDAG::dump to see<br class="">exactly what it's created. Then try to work out where that gets<br class="">pessimized to shifts, because it's not normal.<br class=""><br class="">Cheers.<br class=""><br class="">Tim.<br class=""></div></div></blockquote></div><br class=""></div></div></body></html>