Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4079764
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:50:37+00:00 2026-05-20T17:50:37+00:00

I’m trying to use vectors inside structs with LLVM. I have the following C

  • 0

I’m trying to use vectors inside structs with LLVM. I have the following C definition of my struct:

struct Foo
{
    uint32_t len;
    uint32_t data[32] __attribute__ ((aligned (16)));
};

and here’s some LLVM code to add 42 to element number 3 of the data field:

%Foo = type { i32, <32 x i32> }

define void @process(%Foo*) {
_L1:
  %data = getelementptr %Foo* %0, i32 0, i32 1
  %vec = load <32 x i32>* %data
  %x = extractelement <32 x i32> %vec, i32 3
  %xNew = add i32 42, %x
  %vecNew = insertelement <32 x i32> %vec, i32 %xNew, i32 3
  store <32 x i32> %vecNew, <32 x i32>* %data
  ret void
}

However, the output of llc is as if vectors had to be aligned at 128 bytes, which seems wasteful, and also wrong (AFAIK vectors should be 16-byte-aligned):

    .file   "process.bc"
    .text
    .globl  process
    .align  16, 0x90
    .type   process,@function
process:                                # @process
.Leh_func_begin0:
# BB#0:                                 # %_L1
    movdqa  128(%rdi), %xmm0
    pextrd  $3, %xmm0, %eax
    addl    $42, %eax
    pinsrd  $3, %eax, %xmm0
    movdqa  %xmm0, 128(%rdi)
    ret
.Ltmp0:
    .size   process, .Ltmp0-process
.Leh_func_end0:

Of course, if I change the C definition to also align the data field at 128 bytes, it works, but wasting 124 bytes (compared to 12 if using 16-byte alignment) just seems wrong. So what’s going on here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:50:38+00:00Added an answer on May 20, 2026 at 5:50 pm

    I think your GEPs are a little off for the best codegen. Here’s some C code that does something similar:

    #include <stdint.h>
    
    struct Foo
    {
      uint32_t len;
      uint32_t data[32] __attribute__ ((aligned (16)));
    };
    
    void foo(struct Foo *F)
    {
      F->data[3] = 4;
    }
    

    which clang turns into this:

    ; ModuleID = 'foo.c'
    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-apple-darwin10.0.0"
    
    %struct.Foo = type { i32, [12 x i8], [32 x i32] }
    
    define void @foo(%struct.Foo* %F) nounwind ssp {
      %1 = alloca %struct.Foo*, align 8
      store %struct.Foo* %F, %struct.Foo** %1, align 8
      %2 = load %struct.Foo** %1, align 8
      %3 = getelementptr inbounds %struct.Foo* %2, i32 0, i32 2
      %4 = getelementptr inbounds [32 x i32]* %3, i32 0, i64 3
      store i32 4, i32* %4
      ret void
    }
    

    and the corresponding nice code you’d expect:

    _foo:                                   ## @foo
    Leh_func_begin0:
    ## BB#0:
        pushq   %rbp
    Ltmp0:
        movq    %rsp, %rbp
    Ltmp1:
        movl    $4, 28(%rdi)
        popq    %rbp
        ret
    Leh_func_end0:
    

    That said, the code you have there is isn’t right and should be:

    _process:                               ## @process
    Leh_func_begin1:
    ## BB#0:                                ## %_L1
            movaps  16(%rdi), %xmm0
            pextrd  $3, %xmm0, %eax
            addl    $42, %eax
            pinsrd  $3, %eax, %xmm0
            movaps  %xmm0, 16(%rdi)
            ret
    

    and is even worse in ToT so a bug report wouldn’t go amiss there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.