Skip to content

Bad-quality code passing union as argument on x86_64 #3971

@efriedma-quic

Description

@efriedma-quic
Bugzilla Link 3599
Resolution FIXED
Resolved on Feb 17, 2009 14:48
Version unspecified
OS Linux

Extended Description

union UGeckoInstruction
{
unsigned hex;
};
unsigned a(union UGeckoInstruction a) {return a.hex;}

Run through clang -emit-llvm -O2 -arch=x86_64, gives the following:
; ModuleID = '-'
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-f80:128:128"
target triple = "x86_64-pc-linux-gnu"

define i32 @​a(i64) nounwind readnone {
entry:
%tmp5 = trunc i64 %0 to i8 ; [#uses=1]
%tmp7 = lshr i64 %0, 8 ; [#uses=1]
%tmp8 = trunc i64 %tmp7 to i8 ; [#uses=1]
%tmp10 = lshr i64 %0, 16 ; [#uses=1]
%tmp11 = trunc i64 %tmp10 to i8 ; [#uses=1]
%tmp13 = lshr i64 %0, 24 ; [#uses=1]
%tmp14 = trunc i64 %tmp13 to i8 ; [#uses=1]
%1 = zext i8 %tmp5 to i32 ; [#uses=1]
%2 = zext i8 %tmp8 to i32 ; [#uses=1]
%3 = shl i32 %2, 8 ; [#uses=1]
%4 = zext i8 %tmp11 to i32 ; [#uses=1]
%5 = shl i32 %4, 16 ; [#uses=1]
%6 = zext i8 %tmp14 to i32 ; [#uses=1]
%7 = shl i32 %6, 24 ; [#uses=1]
%8 = or i32 %7, %1 ; [#uses=1]
%9 = or i32 %8, %5 ; [#uses=1]
%10 = or i32 %9, %3 ; [#uses=1]
ret i32 %10
}

This is rather silly. I'm not sure whether to blame clang or the LLVM optimizers for this result, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:codegenIR generation bugs: mangling, exceptions, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions