LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 50817 - Failure to perform extract with variable index from splat vector
Summary: Failure to perform extract with variable index from splat vector
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: PC Windows NT
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-23 06:42 PDT by Simon Pilgrim
Modified: 2021-07-05 05:31 PDT (History)
2 users (show)

See Also:
Fixed By Commit(s): 3d3c0ed9323b


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Pilgrim 2021-06-23 06:42:57 PDT
https://c.godbolt.org/z/rq43Wqc5a

#include <x86intrin.h>

auto adjust_splat(float x, float y, int i) {
    __m128 r = _mm_set1_ps(x);
    r[i & 3] += y;
    return r;
}
auto adjust_splat2(float x, float y, int i) {
    __m128 r = _mm_set1_ps(x);
    r[i & 3] = x + y;
    return r;
}

If the variable-index of an extract from a splatted vector is known to be inrange, we should be safe to use the original scalar directly. 

Not sure if this can be done in IR or we wait until SelectionDAG?
Comment 1 Sanjay Patel 2021-06-24 11:02:31 PDT
The splat removal should be in IR:
https://reviews.llvm.org/D104867

I'm not seeing what we want to do with the "adjust_splat2" example?
Comment 2 Simon Pilgrim 2021-06-24 13:55:43 PDT
(In reply to Sanjay Patel from comment #1)

> I'm not seeing what we want to do with the "adjust_splat2" example?

adjust_splat2 was just for reference to show the possible codegen if adjust_splat managed to extract the splatted value
Comment 3 Sanjay Patel 2021-07-05 05:31:46 PDT
Fixed in IR with:
https://reviews.llvm.org/rG3d3c0ed9323b