This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Don't cast and use SizeTy instead of Int32Ty when constructing {extract,insert} vector element instructions.
ClosedPublic

Authored by Bigcheese on May 30 2014, 4:53 PM.

Details

Reviewers
chandlerc
rsmith
Summary

With this patch the following code is able to be correctly optimized.

#include <x86intrin.h>
#include <immintrin.h>
#include <avxintrin.h>
#include <avx2intrin.h>
#include <cstdio>
#include <cinttypes>

__m128 bss4( const __m128 *ptr, size_t i, size_t j )
{
    float f = ptr[i][j];
    return (__m128) { f, f, f, f };
}

Previously an unneeded trunc + zext would be emitted.

Diff Detail

Event Timeline

Bigcheese updated this revision to Diff 9971.May 30 2014, 4:53 PM
Bigcheese retitled this revision from to [CodeGen] Don't cast and use SizeTy instead of Int32Ty when constructing {extract,insert} vector element instructions. .
Bigcheese updated this object.
Bigcheese edited the test plan for this revision. (Show Details)
Bigcheese added a reviewer: rsmith.
Bigcheese added a subscriber: Unknown Object (MLST).
chandlerc accepted this revision.May 30 2014, 5:13 PM
chandlerc added a reviewer: chandlerc.
chandlerc added a subscriber: chandlerc.

This seems like a strict improvement. Is there ever a case where the incoming index size would not be SizeTy? I wonder if we should use its type directly, even if just for clarity, to indicate that the goal is to use whatever integer size we already have.

This revision is now accepted and ready to land.May 30 2014, 5:13 PM

This patch uses the incoming index's type unless it's creating a constant.

Bigcheese closed this revision.May 30 2014, 5:48 PM

Committed as r209942.

Cool, LGTM. Maybe add tests to verify that we use a narrow integer when an incoming index is a narrow integer variable. Submit whenever.