<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/139202>139202</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SLPV] Pointer offsets truncated to 32-bits, resulting in wrong code
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rnk
</td>
</tr>
</table>
<pre>
Consider:
```
$ cat t.ll
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-grtev4-linux-gnu"
define void @_ZN12_GLOBAL__N_111LargeObjectILm4294967296EEC2Em(ptr %this) #0 {
entry:
store i64 1, ptr %this, align 8
%b = getelementptr i8, ptr %this, i64 8
store i64 2, ptr %b, align 8
%c = getelementptr i8, ptr %this, i64 u0x100000010
store i64 3, ptr %c, align 8
%d = getelementptr i8, ptr %this, i64 u0x100000018
store i64 4, ptr %d, align 8
ret void
}
attributes #0 = { "target-features"="+aes,+avx,+cmov,+crc32,+cx16,+cx8,+fxsr,+mmx,+pclmul,+popcnt,+prfchw,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" }
$ opt -passes=slp-vectorizer t.ll -S -o -
; ModuleID = 't.ll'
source_filename = "t.ll"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-grtev4-linux-gnu"
define void @_ZN12_GLOBAL__N_111LargeObjectILm4294967296EEC2Em(ptr %this) #0 {
entry:
store <4 x i64> <i64 1, i64 2, i64 3, i64 4>, ptr %this, align 8
ret void
}
attributes #0 = { "target-features"="+aes,+avx,+cmov,+crc32,+cx16,+cx8,+fxsr,+mmx,+pclmul,+popcnt,+prfchw,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" }
```
Clearly, somewhere inside SLPV, the GEP offsets here are truncated from 64-bits to 32. To quickly check SLPV with static analysis, I did this:
```
$ ninja opt # build everything once
$ touch ../llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
$ CCC_OVERRIDE_OPTIONS='+-Wshorten-64-to-32' ninja opt | tee slpv-truncations.txt
...
```
Unfortunately, there are 733 hits:
```
$ grep warning: slpv-truncations.txt | wc -l
733
```
This is not a recent regression, it goes back to LLVM 14 and earlier: https://godbolt.org/z/9baE551T7 LLVM 14 is just as far back as the IR is parseable out of the box.
I think the next move here would be to do a global search & replace of getZExtValue with some variant that asserts when the result is wider than 32-bits, or to focus only on the warnings that include getZExtValue in the warning text snippet.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsVs1u4zgSfhr6UpAhUbJkHXxw_DMIkOk0urNZYC4GJZUldihSS5ZsZ55-QcpxJ929WMycJzCUj2L9qaq-IoVzstWIK7a4Y4vtTIzUGbuy-mVWmeZ1tTHayQYtS9csDr88vv7iNeMZ1IKA5kqxeE3CtkjQCBJKvJqRgKVbYJxj1LN0jdHAi5il65SHh18mH5ce5Vl4RPIGEr5k6Trhy-i4jK9Ih1f5m3qeRV-9GOff4yArB4VvMVyW-SHPotYSnrJIST1eolaPkwaL1w0epUY4GdkAy-LDH58Sfvjt4fFu_XA4fDokSfLgzT5W37Cm-4c-42VW5gUv891uw3c948uBLDC-oE46xktgPI2BFXcsXqMm-zqlEBwZiyDzDBLGN_BBaQNCyVbD0gv611UIv0VChT1q8tJy-Qs9b2_50Tx_J1b9wnb9V2yP8SWJw18SBwPf_aTvVOpf-Gn-pp_lD36ydyrNj34sUqidL2axnUoqiKysRkJ3rYXvhOLOd8PUItERBY0Wne-CdOuf_E745caD02UCdW9OV2TrlF_hJcnf0HICx4uzE-r7q-pQq35UV2yGWtMV22PdnSfsHN4Av6H0hrJ58g7fJG4il2VxBU6ckHEOtwx4gpqBIBqEc-hYunVqiE5Yk7HyT7SBuQDRV4gMRF4hvYPfTTMqvN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