[cfe-dev] MRV on x86_64

Arushi Aggarwal arushi987 at gmail.com
Thu Mar 10 10:09:21 PST 2011


Hi,

I am using clang on the following code,

struct S {
  float a,b,c;
};

void foo(struct S obj) {
  obj.a = 1.2;
}

int main() {
  struct S s;
  s.a = 1.0;
  s.b = 1.0;
  s.c = 1.0;
  foo(s);
  return 0;
}

The generated code for foo, changes the type of the argument to foo to be
{double, double} .

llvm-gcc was converting this to {double, float} which was an ABI
requirement, as par an older discussion(
http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-January/028870.html)

Why does clang change it to a struct with a different size?

The generated IR is below.

Thanks
Arushi


; ModuleID = 'mrv.cpp'
target datalayout =
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-unknown-linux-gnu"

%0 = type { double, double }
%struct.S = type { float, float, float }

define void @_Z3foo1S(%0) {
entry:
  %obj = alloca %struct.S, align 4                ; <%struct.S*> [#uses=2]
  %tmp = alloca %0                                ; <%0*> [#uses=2]
  store %0 %0, %0* %tmp
  %1 = bitcast %0* %tmp to %struct.S*             ; <%struct.S*> [#uses=1]
  %2 = load %struct.S* %1, align 1                ; <%struct.S> [#uses=1]
  store %struct.S %2, %struct.S* %obj
  %tmp1 = getelementptr inbounds %struct.S* %obj, i32 0, i32 0 ; <float*>
[#uses=1]
  store float 0x3FF3333340000000, float* %tmp1
  ret void
}

define i32 @main() {
entry:
  %retval = alloca i32, align 4                   ; <i32*> [#uses=3]
  %s = alloca %struct.S, align 4                  ; <%struct.S*> [#uses=4]
  %agg.tmp = alloca %struct.S, align 4            ; <%struct.S*> [#uses=2]
  %tmp5 = alloca %0                               ; <%0*> [#uses=2]
  store i32 0, i32* %retval
  %tmp = getelementptr inbounds %struct.S* %s, i32 0, i32 0 ; <float*>
[#uses=1]
  store float 1.000000e+00, float* %tmp
  %tmp1 = getelementptr inbounds %struct.S* %s, i32 0, i32 1 ; <float*>
[#uses=1]
  store float 1.000000e+00, float* %tmp1
  %tmp2 = getelementptr inbounds %struct.S* %s, i32 0, i32 2 ; <float*>
[#uses=1]
  store float 1.000000e+00, float* %tmp2
  %tmp3 = bitcast %struct.S* %agg.tmp to i8*      ; <i8*> [#uses=1]
  %tmp4 = bitcast %struct.S* %s to i8*            ; <i8*> [#uses=1]
  call void @llvm.memcpy.i64(i8* %tmp3, i8* %tmp4, i64 12, i32 4)
  %0 = bitcast %0* %tmp5 to %struct.S*            ; <%struct.S*> [#uses=1]
  %1 = load %struct.S* %agg.tmp                   ; <%struct.S> [#uses=1]
  store %struct.S %1, %struct.S* %0, align 1
  %2 = load %0* %tmp5                             ; <%0> [#uses=1]
  call void @_Z3foo1S(%0 %2)
  store i32 0, i32* %retval
  %3 = load i32* %retval                          ; <i32> [#uses=1]
  ret i32 %3
}

declare void @llvm.memcpy.i64(i8* nocapture, i8* nocapture, i64, i32)
nounwind
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110310/8fd7e417/attachment.html>


More information about the cfe-dev mailing list