[llvm] [InstCombine]Fold bitcast shuffle ashr v2i64 (PR #206717)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 6 10:47:45 PDT 2026
cardigan1008 wrote:
Hi @AntonyCJ30 , there seems to be related miscompilation caused by your patch:
ORIGINAL IR:
```llvm
target datalayout = "E-m:e-p:64:64-i64:64-n32:64"
define <2 x i64> @test(<2 x i64> %x) {
%narrow = bitcast <2 x i64> %x to <4 x i32>
%shifted = ashr <4 x i32> %narrow, <i32 0, i32 31, i32 0, i32 31>
%shuf = shufflevector <4 x i32> %shifted, <4 x i32> poison, <4 x i32> <i32 1, i32 1, i32 3, i32 3>
%wide = bitcast <4 x i32> %shuf to <2 x i64>
ret <2 x i64> %wide
}
```
TRANSFORMED IR:
```llvm
; ModuleID = '/data/tmp/tmpzo91t4b6/orig.ll'
source_filename = "/data/tmp/tmpzo91t4b6/orig.ll"
target datalayout = "E-m:e-p:64:64-i64:64-n32:64"
define <2 x i64> @test(<2 x i64> %x) {
%wide = ashr <2 x i64> %x, splat (i64 63)
ret <2 x i64> %wide
}
```
The patch structurally validates the shift vector and shuffle mask but does not validate the datalayout endianness. The recognized mask/shift pattern is the little-endian X86 emulation pattern; applying it on big-endian targets selects the low half rather than the high half.
For more details, please refer to https://archer.top/pr/206717
> Found with [Archer](https://github.com/cuhk-s3/Archer). Please let me know if anything is wrong.
https://github.com/llvm/llvm-project/pull/206717
More information about the llvm-commits
mailing list