Skip to content

Commit 4ff7ac2

Browse files
committed
[SeparateConstOffsetFromGEP] Add test case with trunc nuw/nsw showing miscompile
Pre commit a test case for issue #154116. When redistributing trunc over add/sub/or we may need to drop poison generating flags from the trunc.
1 parent 8d7df8b commit 4ff7ac2

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1200 -passes=separate-const-offset-from-gep -S | FileCheck %s
3+
4+
; FIXME: (add (trunc nuw A), (trunc nuw B)) is more poisonous than
5+
; (trunc nuw (add A, B))), so we should for example drop the
6+
; nuw on the trunc when doing the rewrite here.
7+
define ptr @pr154116_nuw(ptr %p, i128 %i) {
8+
; CHECK-LABEL: define ptr @pr154116_nuw(
9+
; CHECK-SAME: ptr [[P:%.*]], i128 [[I:%.*]]) #[[ATTR0:[0-9]+]] {
10+
; CHECK-NEXT: [[TMP1:%.*]] = trunc nuw i128 [[I]] to i64
11+
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr i32, ptr [[P]], i64 [[TMP1]]
12+
; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr i8, ptr [[TMP2]], i64 80
13+
; CHECK-NEXT: ret ptr [[ARRAYIDX2]]
14+
;
15+
%idx = add i128 %i, 20
16+
%idx.conv = trunc nuw i128 %idx to i64
17+
%arrayidx = getelementptr i32, ptr %p, i64 %idx.conv
18+
ret ptr %arrayidx
19+
}
20+
21+
; FIXME: (add (trunc nsw A), (trunc nsw B)) is more poisonous than
22+
; (trunc nsw (add A, B))), so we should for example drop the
23+
; nsw on the trunc when doing the rewrite here.
24+
define ptr @pr154116_nsw(ptr %p, i128 %i) {
25+
; CHECK-LABEL: define ptr @pr154116_nsw(
26+
; CHECK-SAME: ptr [[P:%.*]], i128 [[I:%.*]]) #[[ATTR0]] {
27+
; CHECK-NEXT: [[TMP1:%.*]] = trunc nsw i128 [[I]] to i64
28+
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr i32, ptr [[P]], i64 [[TMP1]]
29+
; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr i8, ptr [[TMP2]], i64 4
30+
; CHECK-NEXT: ret ptr [[ARRAYIDX2]]
31+
;
32+
%idx = add i128 %i, 1
33+
%idx.conv = trunc nsw i128 %idx to i64
34+
%arrayidx = getelementptr i32, ptr %p, i64 %idx.conv
35+
ret ptr %arrayidx
36+
}

0 commit comments

Comments
 (0)