Files
clang-p2996/llvm/test/Transforms/InstSimplify/ConstProp/gep.ll
Nikita Popov 10f315dc9c [ConstantFolding] Infer getelementptr nuw flag (#119214)
Infer nuw from nusw and nneg. This is the constant expression variant of
https://github.com/llvm/llvm-project/pull/111144.

Proof: https://alive2.llvm.org/ce/z/ihztLy
2024-12-09 16:44:05 +01:00

32 lines
1.1 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=instcombine -S -o - %s | FileCheck %s
; Tests that we preserve the inrange attribute on indices where possible.
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%struct.A = type { ptr }
@vt = external global [3 x ptr]
define ptr @f0() {
; CHECK-LABEL: @f0(
; CHECK-NEXT: ret ptr getelementptr inbounds nuw inrange(-16, 8) (i8, ptr @vt, i64 16)
;
ret ptr getelementptr (ptr, ptr getelementptr inbounds inrange(-8, 16) ([3 x ptr], ptr @vt, i64 0, i64 1), i64 1)
}
define ptr @f1() {
; CHECK-LABEL: @f1(
; CHECK-NEXT: ret ptr getelementptr inbounds nuw inrange(-8, 0) (i8, ptr @vt, i64 16)
;
ret ptr getelementptr (ptr, ptr getelementptr inbounds inrange(0, 8) ([3 x ptr], ptr @vt, i64 0, i64 1), i64 1)
}
define ptr @f2() {
; CHECK-LABEL: @f2(
; CHECK-NEXT: ret ptr getelementptr inrange(-24, -16) (i8, ptr @vt, i64 32)
;
ret ptr getelementptr (ptr, ptr getelementptr inbounds inrange(0, 8) ([3 x ptr], ptr @vt, i64 0, i64 1), i64 3)
}