<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/113624>113624</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Scalarizer][Bug] Only scatter/gather in extract value for trivially vectorizable intrinsics
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            farzonl
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          farzonl
      </td>
    </tr>
</table>

<pre>
    ## Issue
Today we scatter/gather all extract values of struct return types. Thats out of lock step with how we split the call. The fix is to check if the call was trivially vectorizable before. handling the extract element case.

## Background
 > This is rather assert while we are doing `Scatterer::operator[]` and we are creating `CreateExtractElement` but Type is not a Vector but a Structure. Adding `uadd.with.overflow` to `isTriviallyScalarizable` is 'fixing' this. 

Thats a bug.  Adding to `isTriviallyScalarizable` is not the right fix. Whats going on is because `uadd.with.overflow` isn't in `isTriviallyScalarizable` we aren't splitting the calls so when we call `Scatterer Op0` it isn't operating on the right type. A correct fix wouldn't replace extract element unless we scalarized the call. How long can you wait for a fix? I'm at a conference right now so limited with how quickly I can get a fix out.

Test case:
```
define <3 x i32> @test_(<3 x i32> %a, <3 x i32> %b) {
  %r = call { <3 x i32>, <3 x i1> } @llvm.uadd.with.overflow.v3i32(<3 x i32> %b, <3 x i32> %b)
  %el = extractvalue { <3 x i32>, <3 x i1> } %r, 0
  ret <3 x i32> %el
}
```

```
./build/bin/opt -passes='function(scalarizer)' ./build/test_fail.ll -S
opt: ./llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From *) [To = llvm::VectorType, From = llvm::Type]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
```


_Originally posted by @farzonl in https://github.com/llvm/llvm-project/issues/111569#issuecomment-2436239121_
 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVs2O4jgQfhpz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