This patch folds the X86 pre-AVX512 64-bit vector arithmetic shift emulation pattern (bitcast(shuffle(ashr(bitcast(X))))) into a single ashr instruction. The transformation is implemented in InstCombine, the middle-end optimization pass, so it benefits all backends (X86, ARM, RISC-V, etc.) by cleaning up the IR before it reaches any target-specific lowering.
Alive2 proof: https://alive2.llvm.org/ce/z/LM1Eu1
Fixes: #125189
The new InstCombine fold assumes that bitcast <1 x i64> %x to <2 x i32> maps element 1 to the high/sign-containing half of the i64 lane. That is only true for little-endian layouts. LLVM LangRef defines vector bitcasts as endian-sensitive: on big-endian, element 0 contains the high bits and element 1 contains the low bits.
With the big-endian datalayout above, for %x = <i64 0x0000000080000000>:
<i32 0, i32 0x80000000>; ashr by <0,31> yields <0,-1>; shuffle <1,1> yields <-1,-1>; bitcast back yields <i64 -1>.ashr <1 x i64> %x, splat(63), which yields <i64 0>.Alive2 reports this exact value mismatch, so the transformation is unsound.
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. The same issue also applies to multi-lane <N x i64> and to the generalized non-i64 widths accepted by the implementation, such as <1 x i32> via <2 x i16>. The fold should either be restricted to little-endian datalayouts or use an endian-aware mask/shift interpretation.
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
}; 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
}
----------------------------------------
define <2 x i64> @test(<2 x i64> %x) {
#0:
%narrow = bitcast <2 x i64> %x to <4 x i32>
%shifted = ashr <4 x i32> %narrow, { 0, 31, 0, 31 }
%shuf = shufflevector <4 x i32> %shifted, <4 x i32> poison, 1, 1, 3, 3
%wide = bitcast <4 x i32> %shuf to <2 x i64>
ret <2 x i64> %wide
}
=>
define <2 x i64> @test(<2 x i64> %x) {
#0:
%wide = ashr <2 x i64> %x, { 63, 63 }
ret <2 x i64> %wide
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
<2 x i64> %x = < #x0000000000000000 (0), #x0000000080000000 (2147483648) >
Source:
<4 x i32> %narrow = < #x00000000 (0), #x00000000 (0), #x00000000 (0), #x80000000 (2147483648, -2147483648) >
<4 x i32> %shifted = < #x00000000 (0), #x00000000 (0), #x00000000 (0), #xffffffff (4294967295, -1) >
<4 x i32> %shuf = < #x00000000 (0), #x00000000 (0), #xffffffff (4294967295, -1), #xffffffff (4294967295, -1) >
<2 x i64> %wide = < #x0000000000000000 (0), #xffffffffffffffff (18446744073709551615, -1) >
Target:
<2 x i64> %wide = < #x0000000000000000 (0), #x0000000000000000 (0) >
Source value: < #x0000000000000000 (0), #xffffffffffffffff (18446744073709551615, -1) >
Target value: < #x0000000000000000 (0), #x0000000000000000 (0) >
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errorstarget datalayout = "E-m:e-p:64:64-i64:64-n32:64"
define <1 x i64> @be_v1_low_sign(<1 x i64> %x) {
%narrow = bitcast <1 x i64> %x to <2 x i32>
%shifted = ashr <2 x i32> %narrow, <i32 0, i32 31>
%shuf = shufflevector <2 x i32> %shifted, <2 x i32> poison, <2 x i32> <i32 1, i32 1>
%wide = bitcast <2 x i32> %shuf to <1 x i64>
ret <1 x i64> %wide
}; ModuleID = '/data/tmp/tmpzo6h_adv/orig.ll'
source_filename = "/data/tmp/tmpzo6h_adv/orig.ll"
target datalayout = "E-m:e-p:64:64-i64:64-n32:64"
define <1 x i64> @be_v1_low_sign(<1 x i64> %x) {
%wide = ashr <1 x i64> %x, splat (i64 63)
ret <1 x i64> %wide
}
----------------------------------------
define <1 x i64> @be_v1_low_sign(<1 x i64> %x) {
#0:
%narrow = bitcast <1 x i64> %x to <2 x i32>
%shifted = ashr <2 x i32> %narrow, { 0, 31 }
%shuf = shufflevector <2 x i32> %shifted, <2 x i32> poison, 1, 1
%wide = bitcast <2 x i32> %shuf to <1 x i64>
ret <1 x i64> %wide
}
=>
define <1 x i64> @be_v1_low_sign(<1 x i64> %x) {
#0:
%wide = ashr <1 x i64> %x, { 63 }
ret <1 x i64> %wide
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
<1 x i64> %x = < #x0000000080000000 (2147483648) >
Source:
<2 x i32> %narrow = < #x00000000 (0), #x80000000 (2147483648, -2147483648) >
<2 x i32> %shifted = < #x00000000 (0), #xffffffff (4294967295, -1) >
<2 x i32> %shuf = < #xffffffff (4294967295, -1), #xffffffff (4294967295, -1) >
<1 x i64> %wide = < #xffffffffffffffff (18446744073709551615, -1) >
Target:
<1 x i64> %wide = < #x0000000000000000 (0) >
Source value: < #xffffffffffffffff (18446744073709551615, -1) >
Target value: < #x0000000000000000 (0) >
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errorstarget datalayout = "E-m:e-p:64:64-i64:64-n32:64"
define <1 x i64> @be_v1_high_sign(<1 x i64> %x) {
%narrow = bitcast <1 x i64> %x to <2 x i32>
%shifted = ashr <2 x i32> %narrow, <i32 0, i32 31>
%shuf = shufflevector <2 x i32> %shifted, <2 x i32> poison, <2 x i32> <i32 1, i32 1>
%wide = bitcast <2 x i32> %shuf to <1 x i64>
ret <1 x i64> %wide
}; ModuleID = '/data/tmp/tmp7j0jctq3/orig.ll'
source_filename = "/data/tmp/tmp7j0jctq3/orig.ll"
target datalayout = "E-m:e-p:64:64-i64:64-n32:64"
define <1 x i64> @be_v1_high_sign(<1 x i64> %x) {
%wide = ashr <1 x i64> %x, splat (i64 63)
ret <1 x i64> %wide
}
----------------------------------------
define <1 x i64> @be_v1_high_sign(<1 x i64> %x) {
#0:
%narrow = bitcast <1 x i64> %x to <2 x i32>
%shifted = ashr <2 x i32> %narrow, { 0, 31 }
%shuf = shufflevector <2 x i32> %shifted, <2 x i32> poison, 1, 1
%wide = bitcast <2 x i32> %shuf to <1 x i64>
ret <1 x i64> %wide
}
=>
define <1 x i64> @be_v1_high_sign(<1 x i64> %x) {
#0:
%wide = ashr <1 x i64> %x, { 63 }
ret <1 x i64> %wide
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
<1 x i64> %x = < #x0000000080000000 (2147483648) >
Source:
<2 x i32> %narrow = < #x00000000 (0), #x80000000 (2147483648, -2147483648) >
<2 x i32> %shifted = < #x00000000 (0), #xffffffff (4294967295, -1) >
<2 x i32> %shuf = < #xffffffff (4294967295, -1), #xffffffff (4294967295, -1) >
<1 x i64> %wide = < #xffffffffffffffff (18446744073709551615, -1) >
Target:
<1 x i64> %wide = < #x0000000000000000 (0) >
Source value: < #xffffffffffffffff (18446744073709551615, -1) >
Target value: < #x0000000000000000 (0) >
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errorstarget datalayout = "E-m:e-p:64:64-i64:64-n32:64"
define i64 @be_v1_extract(<1 x i64> %x) {
%narrow = bitcast <1 x i64> %x to <2 x i32>
%shifted = ashr <2 x i32> %narrow, <i32 0, i32 31>
%shuf = shufflevector <2 x i32> %shifted, <2 x i32> poison, <2 x i32> <i32 1, i32 1>
%wide = bitcast <2 x i32> %shuf to <1 x i64>
%r = extractelement <1 x i64> %wide, i32 0
ret i64 %r
}; ModuleID = '/data/tmp/tmpteoei864/orig.ll'
source_filename = "/data/tmp/tmpteoei864/orig.ll"
target datalayout = "E-m:e-p:64:64-i64:64-n32:64"
define i64 @be_v1_extract(<1 x i64> %x) {
%1 = extractelement <1 x i64> %x, i64 0
%r = ashr i64 %1, 63
ret i64 %r
}
----------------------------------------
define i64 @be_v1_extract(<1 x i64> %x) {
#0:
%narrow = bitcast <1 x i64> %x to <2 x i32>
%shifted = ashr <2 x i32> %narrow, { 0, 31 }
%shuf = shufflevector <2 x i32> %shifted, <2 x i32> poison, 1, 1
%wide = bitcast <2 x i32> %shuf to <1 x i64>
%r = extractelement <1 x i64> %wide, i32 0
ret i64 %r
}
=>
define i64 @be_v1_extract(<1 x i64> %x) {
#0:
%#1 = extractelement <1 x i64> %x, i64 0
%r = ashr i64 %#1, 63
ret i64 %r
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
<1 x i64> %x = < #x0000000080000000 (2147483648) >
Source:
<2 x i32> %narrow = < #x00000000 (0), #x80000000 (2147483648, -2147483648) >
<2 x i32> %shifted = < #x00000000 (0), #xffffffff (4294967295, -1) >
<2 x i32> %shuf = < #xffffffff (4294967295, -1), #xffffffff (4294967295, -1) >
<1 x i64> %wide = < #xffffffffffffffff (18446744073709551615, -1) >
i64 %r = #xffffffffffffffff (18446744073709551615, -1)
Target:
i64 %#1 = #x0000000080000000 (2147483648)
i64 %r = #x0000000000000000 (0)
Source value: #xffffffffffffffff (18446744073709551615, -1)
Target value: #x0000000000000000 (0)
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errorstarget datalayout = "E-m:e-p:64:64-i64:64-n32:64"
define <1 x i32> @be_i32_i16(<1 x i32> %x) {
%narrow = bitcast <1 x i32> %x to <2 x i16>
%shifted = ashr <2 x i16> %narrow, <i16 0, i16 15>
%shuf = shufflevector <2 x i16> %shifted, <2 x i16> poison, <2 x i32> <i32 1, i32 1>
%wide = bitcast <2 x i16> %shuf to <1 x i32>
ret <1 x i32> %wide
}; ModuleID = '/data/tmp/tmpf3w2fxmv/orig.ll'
source_filename = "/data/tmp/tmpf3w2fxmv/orig.ll"
target datalayout = "E-m:e-p:64:64-i64:64-n32:64"
define <1 x i32> @be_i32_i16(<1 x i32> %x) {
%wide = ashr <1 x i32> %x, splat (i32 31)
ret <1 x i32> %wide
}
----------------------------------------
define <1 x i32> @be_i32_i16(<1 x i32> %x) {
#0:
%narrow = bitcast <1 x i32> %x to <2 x i16>
%shifted = ashr <2 x i16> %narrow, { 0, 15 }
%shuf = shufflevector <2 x i16> %shifted, <2 x i16> poison, 1, 1
%wide = bitcast <2 x i16> %shuf to <1 x i32>
ret <1 x i32> %wide
}
=>
define <1 x i32> @be_i32_i16(<1 x i32> %x) {
#0:
%wide = ashr <1 x i32> %x, { 31 }
ret <1 x i32> %wide
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
<1 x i32> %x = < #x00008000 (32768) >
Source:
<2 x i16> %narrow = < #x0000 (0), #x8000 (32768, -32768) >
<2 x i16> %shifted = < #x0000 (0), #xffff (65535, -1) >
<2 x i16> %shuf = < #xffff (65535, -1), #xffff (65535, -1) >
<1 x i32> %wide = < #xffffffff (4294967295, -1) >
Target:
<1 x i32> %wide = < #x00000000 (0) >
Source value: < #xffffffff (4294967295, -1) >
Target value: < #x00000000 (0) >
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errorstarget datalayout = "E-m:e-p:64:64-i64:64-n32:64"
declare void @llvm.assume(i1)
define <1 x i64> @be_v1_high_sign_assume(<1 x i64> %x) {
%e = extractelement <1 x i64> %x, i32 0
%c = icmp eq i64 %e, -9223372036854775808
call void @llvm.assume(i1 %c)
%narrow = bitcast <1 x i64> %x to <2 x i32>
%shifted = ashr <2 x i32> %narrow, <i32 0, i32 31>
%shuf = shufflevector <2 x i32> %shifted, <2 x i32> poison, <2 x i32> <i32 1, i32 1>
%wide = bitcast <2 x i32> %shuf to <1 x i64>
ret <1 x i64> %wide
}; ModuleID = '/data/tmp/tmp0jmdm85c/orig.ll'
source_filename = "/data/tmp/tmp0jmdm85c/orig.ll"
target datalayout = "E-m:e-p:64:64-i64:64-n32:64"
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)
declare void @llvm.assume(i1 noundef) #0
define <1 x i64> @be_v1_high_sign_assume(<1 x i64> %x) {
%e = extractelement <1 x i64> %x, i64 0
%c = icmp eq i64 %e, -9223372036854775808
call void @llvm.assume(i1 %c)
%wide = ashr <1 x i64> %x, splat (i64 63)
ret <1 x i64> %wide
}
attributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }
----------------------------------------
define <1 x i64> @be_v1_high_sign_assume(<1 x i64> %x) {
#0:
%e = extractelement <1 x i64> %x, i32 0
%c = icmp eq i64 %e, -9223372036854775808
assume i1 %c
%narrow = bitcast <1 x i64> %x to <2 x i32>
%shifted = ashr <2 x i32> %narrow, { 0, 31 }
%shuf = shufflevector <2 x i32> %shifted, <2 x i32> poison, 1, 1
%wide = bitcast <2 x i32> %shuf to <1 x i64>
ret <1 x i64> %wide
}
=>
define <1 x i64> @be_v1_high_sign_assume(<1 x i64> %x) {
#0:
%e = extractelement <1 x i64> %x, i64 0
%c = icmp eq i64 %e, -9223372036854775808
assume i1 %c
%wide = ashr <1 x i64> %x, { 63 }
ret <1 x i64> %wide
}
Transformation doesn't verify!
ERROR: Value mismatch
NOTE: The counterexample is unique.
Example:
<1 x i64> %x = < #x8000000000000000 (9223372036854775808, -9223372036854775808) >
Source:
i64 %e = #x8000000000000000 (9223372036854775808, -9223372036854775808)
i1 %c = #x1 (1)
<2 x i32> %narrow = < #x80000000 (2147483648, -2147483648), #x00000000 (0) >
<2 x i32> %shifted = < #x80000000 (2147483648, -2147483648), #x00000000 (0) >
<2 x i32> %shuf = < #x00000000 (0), #x00000000 (0) >
<1 x i64> %wide = < #x0000000000000000 (0) >
Target:
i64 %e = #x8000000000000000 (9223372036854775808, -9223372036854775808)
i1 %c = #x1 (1)
<1 x i64> %wide = < #xffffffffffffffff (18446744073709551615, -1) >
Source value: < #x0000000000000000 (0) >
Target value: < #xffffffffffffffff (18446744073709551615, -1) >
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errorstarget datalayout = "E-m:e-i64:64-n32:64"
define <2 x i64> @be_counter(<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
}; ModuleID = '/data/tmp/tmpr79gciv1/orig.ll'
source_filename = "/data/tmp/tmpr79gciv1/orig.ll"
target datalayout = "E-m:e-i64:64-n32:64"
define <2 x i64> @be_counter(<2 x i64> %x) {
%wide = ashr <2 x i64> %x, splat (i64 63)
ret <2 x i64> %wide
}
----------------------------------------
define <2 x i64> @be_counter(<2 x i64> %x) {
#0:
%narrow = bitcast <2 x i64> %x to <4 x i32>
%shifted = ashr <4 x i32> %narrow, { 0, 31, 0, 31 }
%shuf = shufflevector <4 x i32> %shifted, <4 x i32> poison, 1, 1, 3, 3
%wide = bitcast <4 x i32> %shuf to <2 x i64>
ret <2 x i64> %wide
}
=>
define <2 x i64> @be_counter(<2 x i64> %x) {
#0:
%wide = ashr <2 x i64> %x, { 63, 63 }
ret <2 x i64> %wide
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
<2 x i64> %x = < #x0000000000000000 (0), #x0000000080000000 (2147483648) >
Source:
<4 x i32> %narrow = < #x00000000 (0), #x00000000 (0), #x00000000 (0), #x80000000 (2147483648, -2147483648) >
<4 x i32> %shifted = < #x00000000 (0), #x00000000 (0), #x00000000 (0), #xffffffff (4294967295, -1) >
<4 x i32> %shuf = < #x00000000 (0), #x00000000 (0), #xffffffff (4294967295, -1), #xffffffff (4294967295, -1) >
<2 x i64> %wide = < #x0000000000000000 (0), #xffffffffffffffff (18446744073709551615, -1) >
Target:
<2 x i64> %wide = < #x0000000000000000 (0), #x0000000000000000 (0) >
Source value: < #x0000000000000000 (0), #xffffffffffffffff (18446744073709551615, -1) >
Target value: < #x0000000000000000 (0), #x0000000000000000 (0) >
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errorstarget datalayout = "E"
define <1 x i64> @big_endian_exact(<1 x i64> %x) {
%narrow = bitcast <1 x i64> %x to <2 x i32>
%shifted = ashr <2 x i32> %narrow, <i32 0, i32 31>
%shuf = shufflevector <2 x i32> %shifted, <2 x i32> poison, <2 x i32> <i32 1, i32 1>
%wide = bitcast <2 x i32> %shuf to <1 x i64>
ret <1 x i64> %wide
}; ModuleID = '/data/tmp/tmpusxsjbfj/orig.ll'
source_filename = "/data/tmp/tmpusxsjbfj/orig.ll"
target datalayout = "E"
define <1 x i64> @big_endian_exact(<1 x i64> %x) {
%wide = ashr <1 x i64> %x, splat (i64 63)
ret <1 x i64> %wide
}
----------------------------------------
define <1 x i64> @big_endian_exact(<1 x i64> %x) {
#0:
%narrow = bitcast <1 x i64> %x to <2 x i32>
%shifted = ashr <2 x i32> %narrow, { 0, 31 }
%shuf = shufflevector <2 x i32> %shifted, <2 x i32> poison, 1, 1
%wide = bitcast <2 x i32> %shuf to <1 x i64>
ret <1 x i64> %wide
}
=>
define <1 x i64> @big_endian_exact(<1 x i64> %x) {
#0:
%wide = ashr <1 x i64> %x, { 63 }
ret <1 x i64> %wide
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
<1 x i64> %x = < #x0000000080000000 (2147483648) >
Source:
<2 x i32> %narrow = < #x00000000 (0), #x80000000 (2147483648, -2147483648) >
<2 x i32> %shifted = < #x00000000 (0), #xffffffff (4294967295, -1) >
<2 x i32> %shuf = < #xffffffff (4294967295, -1), #xffffffff (4294967295, -1) >
<1 x i64> %wide = < #xffffffffffffffff (18446744073709551615, -1) >
Target:
<1 x i64> %wide = < #x0000000000000000 (0) >
Source value: < #xffffffffffffffff (18446744073709551615, -1) >
Target value: < #x0000000000000000 (0) >
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errorstarget datalayout = "E"
define <2 x i128> @big_endian_wider(<2 x i128> %x) {
%narrow = bitcast <2 x i128> %x to <4 x i64>
%shifted = ashr <4 x i64> %narrow, <i64 0, i64 63, i64 0, i64 63>
%shuf = shufflevector <4 x i64> %shifted, <4 x i64> poison, <4 x i32> <i32 1, i32 1, i32 3, i32 3>
%wide = bitcast <4 x i64> %shuf to <2 x i128>
ret <2 x i128> %wide
}; ModuleID = '/data/tmp/tmpmt5wcft3/orig.ll'
source_filename = "/data/tmp/tmpmt5wcft3/orig.ll"
target datalayout = "E"
define <2 x i128> @big_endian_wider(<2 x i128> %x) {
%wide = ashr <2 x i128> %x, splat (i128 127)
ret <2 x i128> %wide
}
----------------------------------------
define <2 x i128> @big_endian_wider(<2 x i128> %x) {
#0:
%narrow = bitcast <2 x i128> %x to <4 x i64>
%shifted = ashr <4 x i64> %narrow, { 0, 63, 0, 63 }
%shuf = shufflevector <4 x i64> %shifted, <4 x i64> poison, 1, 1, 3, 3
%wide = bitcast <4 x i64> %shuf to <2 x i128>
ret <2 x i128> %wide
}
=>
define <2 x i128> @big_endian_wider(<2 x i128> %x) {
#0:
%wide = ashr <2 x i128> %x, { 127, 127 }
ret <2 x i128> %wide
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
<2 x i128> %x = < #x00000000000000000000000000000000 (0), #x00000000000000008000000000000000 (9223372036854775808) >
Source:
<4 x i64> %narrow = < #x0000000000000000 (0), #x0000000000000000 (0), #x0000000000000000 (0), #x8000000000000000 (9223372036854775808, -9223372036854775808) >
<4 x i64> %shifted = < #x0000000000000000 (0), #x0000000000000000 (0), #x0000000000000000 (0), #xffffffffffffffff (18446744073709551615, -1) >
<4 x i64> %shuf = < #x0000000000000000 (0), #x0000000000000000 (0), #xffffffffffffffff (18446744073709551615, -1), #xffffffffffffffff (18446744073709551615, -1) >
<2 x i128> %wide = < #x00000000000000000000000000000000 (0), #xffffffffffffffffffffffffffffffff (340282366920938463463374607431768211455, -1) >
Target:
<2 x i128> %wide = < #x00000000000000000000000000000000 (0), #x00000000000000000000000000000000 (0) >
Source value: < #x00000000000000000000000000000000 (0), #xffffffffffffffffffffffffffffffff (340282366920938463463374607431768211455, -1) >
Target value: < #x00000000000000000000000000000000 (0), #x00000000000000000000000000000000 (0) >
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errorstarget datalayout = "E"
define <1 x i64> @be_min(<1 x i64> %x) {
%narrow = bitcast <1 x i64> %x to <2 x i32>
%shifted = ashr <2 x i32> %narrow, <i32 0, i32 31>
%shuf = shufflevector <2 x i32> %shifted, <2 x i32> poison, <2 x i32> <i32 1, i32 1>
%wide = bitcast <2 x i32> %shuf to <1 x i64>
ret <1 x i64> %wide
}; ModuleID = '/data/tmp/tmp_djwj964/orig.ll'
source_filename = "/data/tmp/tmp_djwj964/orig.ll"
target datalayout = "E"
define <1 x i64> @be_min(<1 x i64> %x) {
%wide = ashr <1 x i64> %x, splat (i64 63)
ret <1 x i64> %wide
}
----------------------------------------
define <1 x i64> @be_min(<1 x i64> %x) {
#0:
%narrow = bitcast <1 x i64> %x to <2 x i32>
%shifted = ashr <2 x i32> %narrow, { 0, 31 }
%shuf = shufflevector <2 x i32> %shifted, <2 x i32> poison, 1, 1
%wide = bitcast <2 x i32> %shuf to <1 x i64>
ret <1 x i64> %wide
}
=>
define <1 x i64> @be_min(<1 x i64> %x) {
#0:
%wide = ashr <1 x i64> %x, { 63 }
ret <1 x i64> %wide
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
<1 x i64> %x = < #x0000000080000000 (2147483648) >
Source:
<2 x i32> %narrow = < #x00000000 (0), #x80000000 (2147483648, -2147483648) >
<2 x i32> %shifted = < #x00000000 (0), #xffffffff (4294967295, -1) >
<2 x i32> %shuf = < #xffffffff (4294967295, -1), #xffffffff (4294967295, -1) >
<1 x i64> %wide = < #xffffffffffffffff (18446744073709551615, -1) >
Target:
<1 x i64> %wide = < #x0000000000000000 (0) >
Source value: < #xffffffffffffffff (18446744073709551615, -1) >
Target value: < #x0000000000000000 (0) >
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errorstarget datalayout = "E"
define i64 @be_v2i64_lane0(<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>
%r = extractelement <2 x i64> %wide, i32 0
ret i64 %r
}; ModuleID = '/data/tmp/tmpo9nnn_zp/orig.ll'
source_filename = "/data/tmp/tmpo9nnn_zp/orig.ll"
target datalayout = "E"
define i64 @be_v2i64_lane0(<2 x i64> %x) {
%1 = extractelement <2 x i64> %x, i64 0
%r = ashr i64 %1, 63
ret i64 %r
}
----------------------------------------
define i64 @be_v2i64_lane0(<2 x i64> %x) {
#0:
%narrow = bitcast <2 x i64> %x to <4 x i32>
%shifted = ashr <4 x i32> %narrow, { 0, 31, 0, 31 }
%shuf = shufflevector <4 x i32> %shifted, <4 x i32> poison, 1, 1, 3, 3
%wide = bitcast <4 x i32> %shuf to <2 x i64>
%r = extractelement <2 x i64> %wide, i32 0
ret i64 %r
}
=>
define i64 @be_v2i64_lane0(<2 x i64> %x) {
#0:
%#1 = extractelement <2 x i64> %x, i64 0
%r = ashr i64 %#1, 63
ret i64 %r
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
<2 x i64> %x = < #x0000000080000000 (2147483648), poison >
Source:
<4 x i32> %narrow = < #x00000000 (0), #x80000000 (2147483648, -2147483648), poison, poison >
<4 x i32> %shifted = < #x00000000 (0), #xffffffff (4294967295, -1), poison, poison >
<4 x i32> %shuf = < #xffffffff (4294967295, -1), #xffffffff (4294967295, -1), poison, poison >
<2 x i64> %wide = < #xffffffffffffffff (18446744073709551615, -1), poison >
i64 %r = #xffffffffffffffff (18446744073709551615, -1)
Target:
i64 %#1 = #x0000000080000000 (2147483648)
i64 %r = #x0000000000000000 (0)
Source value: #xffffffffffffffff (18446744073709551615, -1)
Target value: #x0000000000000000 (0)
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errorstarget datalayout = "E"
define i32 @be_i32_i16(<1 x i32> %x) {
%narrow = bitcast <1 x i32> %x to <2 x i16>
%shifted = ashr <2 x i16> %narrow, <i16 0, i16 15>
%shuf = shufflevector <2 x i16> %shifted, <2 x i16> poison, <2 x i32> <i32 1, i32 1>
%wide = bitcast <2 x i16> %shuf to <1 x i32>
%r = extractelement <1 x i32> %wide, i32 0
ret i32 %r
}; ModuleID = '/data/tmp/tmpsw409pqg/orig.ll'
source_filename = "/data/tmp/tmpsw409pqg/orig.ll"
target datalayout = "E"
define i32 @be_i32_i16(<1 x i32> %x) {
%1 = extractelement <1 x i32> %x, i64 0
%r = ashr i32 %1, 31
ret i32 %r
}
----------------------------------------
define i32 @be_i32_i16(<1 x i32> %x) {
#0:
%narrow = bitcast <1 x i32> %x to <2 x i16>
%shifted = ashr <2 x i16> %narrow, { 0, 15 }
%shuf = shufflevector <2 x i16> %shifted, <2 x i16> poison, 1, 1
%wide = bitcast <2 x i16> %shuf to <1 x i32>
%r = extractelement <1 x i32> %wide, i32 0
ret i32 %r
}
=>
define i32 @be_i32_i16(<1 x i32> %x) {
#0:
%#1 = extractelement <1 x i32> %x, i64 0
%r = ashr i32 %#1, 31
ret i32 %r
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
<1 x i32> %x = < #x00008000 (32768) >
Source:
<2 x i16> %narrow = < #x0000 (0), #x8000 (32768, -32768) >
<2 x i16> %shifted = < #x0000 (0), #xffff (65535, -1) >
<2 x i16> %shuf = < #xffff (65535, -1), #xffff (65535, -1) >
<1 x i32> %wide = < #xffffffff (4294967295, -1) >
i32 %r = #xffffffff (4294967295, -1)
Target:
i32 %#1 = #x00008000 (32768)
i32 %r = #x00000000 (0)
Source value: #xffffffff (4294967295, -1)
Target value: #x00000000 (0)
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errors