<div dir="ltr">After a second look, the transformation looks right since "268435455" can be fit into i48.   Thanks.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 15, 2016 at 9:49 AM, Yaoqing Gao <span dir="ltr"><<a href="mailto:yaoqing.gao@gmail.com" target="_blank">yaoqing.gao@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello,<br><br>I am still in process to get an account to access <a href="https://llvm.org/bugs/" target="_blank">https://llvm.org/bugs/</a>.  So I would like to post it here for discussion first.<br><br>It looks there is a problem with "Combine redundant instructions".<br><br>Given the following simple example:<br><br>#include "stdio.h"<br>#include "stdint.h"<br>struct A {<br>  uint8_t pedding;<br>  uint64_t integer:48;<br>}__attribute__ ((__packed__));<br><br>__attribute__((noinline))<br>void foo(struct A * ptr) {<br>  ptr->integer = 1;<br>  ptr->pedding = -1; // this was supposed to be masked away<br>}<br><br>uint64_t C=0xfffffff;<br>int main(int argc, char** argv) {<br>  struct A a;<br>  foo(&a);<br>  if ((uint64_t) a.integer > (uint64_t) 0xfffffff) { <br>    return 1;<br>  }<br>  return 0;<br>}<br><br> "Combine redundant instructions" pass (InstructionCombining.cpp) converts  the statement of  "    if ((uint64_t) a.integer > (uint64_t) 0xfffffff) "<br> from<br>define signext i32 @main(i32 signext, i8**) local_unnamed_addr #1 {<br>  %3 = alloca %struct.A, align 1<br>  %4 = bitcast %struct.A* %3 to i8*<br>  call void @llvm.lifetime.start(i64 7, i8* %4) #3<br>  call void @foo(%struct.A* %3)<br>  %5 = getelementptr inbounds %struct.A, %struct.A* %3, i32 0, i32 1<br>  %6 = bitcast [6 x i8]* %5 to i48*<br>-----<br>  %7 = load i48, i48* %6, align 1<br>  %8 = zext i48 %7 to i64<br>  %9 = icmp ugt i64 %8, 268435455<br>----<br>  br i1 %9, label %10, label %11<br><br>to<br>define signext i32 @main(i32 signext, i8**) local_unnamed_addr #1 {<br>  %3 = alloca %struct.A, align 1<br>  %4 = getelementptr inbounds %struct.A, %struct.A* %3, i64 0, i32 0<br>  call void @llvm.lifetime.start(i64 7, i8* %4) #3<br>  call void @foo(%struct.A* nonnull %3)<br>  %5 = getelementptr inbounds %struct.A, %struct.A* %3, i64 0, i32 1<br>  %6 = bitcast [6 x i8]* %5 to i48*<br>----<br>  %7 = load i48, i48* %6, align 1<br>  %8 = icmp ugt i48 %7, 268435455  <br>-----<br>  br i1 %8, label %9, label %10<br><br><br>Here the icmp instruction has mismatched data type/length (i48 variable and i64 constant).  This problem was found when we try to consume the LLVM IR from LLVM opt.  <br clear="all"><span class="HOEnZb"><font color="#888888"><br>-- <br><div>Best regards,<br><br>Yaoqing Gao</div>
</font></span></div>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Best regards,<br><br>Yaoqing Gao</div>
</div>