Bjorn Pettersson 4ff7ac2330
[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.
2025-08-22 10:26:09 +02:00

37 lines
1.6 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt < %s -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1200 -passes=separate-const-offset-from-gep -S | FileCheck %s
; FIXME: (add (trunc nuw A), (trunc nuw B)) is more poisonous than
; (trunc nuw (add A, B))), so we should for example drop the
; nuw on the trunc when doing the rewrite here.
define ptr @pr154116_nuw(ptr %p, i128 %i) {
; CHECK-LABEL: define ptr @pr154116_nuw(
; CHECK-SAME: ptr [[P:%.*]], i128 [[I:%.*]]) #[[ATTR0:[0-9]+]] {
; CHECK-NEXT: [[TMP1:%.*]] = trunc nuw i128 [[I]] to i64
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr i32, ptr [[P]], i64 [[TMP1]]
; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr i8, ptr [[TMP2]], i64 80
; CHECK-NEXT: ret ptr [[ARRAYIDX2]]
;
%idx = add i128 %i, 20
%idx.conv = trunc nuw i128 %idx to i64
%arrayidx = getelementptr i32, ptr %p, i64 %idx.conv
ret ptr %arrayidx
}
; FIXME: (add (trunc nsw A), (trunc nsw B)) is more poisonous than
; (trunc nsw (add A, B))), so we should for example drop the
; nsw on the trunc when doing the rewrite here.
define ptr @pr154116_nsw(ptr %p, i128 %i) {
; CHECK-LABEL: define ptr @pr154116_nsw(
; CHECK-SAME: ptr [[P:%.*]], i128 [[I:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[TMP1:%.*]] = trunc nsw i128 [[I]] to i64
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr i32, ptr [[P]], i64 [[TMP1]]
; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr i8, ptr [[TMP2]], i64 4
; CHECK-NEXT: ret ptr [[ARRAYIDX2]]
;
%idx = add i128 %i, 1
%idx.conv = trunc nsw i128 %idx to i64
%arrayidx = getelementptr i32, ptr %p, i64 %idx.conv
ret ptr %arrayidx
}