[llvm] 10c99ce - [InstCombine] Fold memrchr calls with constant size, bail on excessive.
Martin Sebor via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 26 13:03:24 PDT 2022
Author: Martin Sebor
Date: 2022-04-26T14:02:50-06:00
New Revision: 10c99ce67d541eb783971f8237b96530b821479a
URL: https://github.com/llvm/llvm-project/commit/10c99ce67d541eb783971f8237b96530b821479a
DIFF: https://github.com/llvm/llvm-project/commit/10c99ce67d541eb783971f8237b96530b821479a.diff
LOG: [InstCombine] Fold memrchr calls with constant size, bail on excessive.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D123626
Differential Revision: https://reviews.llvm.org/D123628
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/memrchr-2.ll
llvm/test/Transforms/InstCombine/memrchr-3.ll
llvm/test/Transforms/InstCombine/memrchr-4.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 8d59a5ed28d04..2ef33c6da236f 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -898,8 +898,41 @@ Value *LibCallSimplifier::optimizeStrStr(CallInst *CI, IRBuilderBase &B) {
}
Value *LibCallSimplifier::optimizeMemRChr(CallInst *CI, IRBuilderBase &B) {
- if (isKnownNonZero(CI->getOperand(2), DL))
- annotateNonNullNoUndefBasedOnAccess(CI, 0);
+ Value *SrcStr = CI->getArgOperand(0);
+ Value *Size = CI->getArgOperand(2);
+ annotateNonNullAndDereferenceable(CI, 0, Size, DL);
+ Value *CharVal = CI->getArgOperand(1);
+ ConstantInt *LenC = dyn_cast<ConstantInt>(Size);
+ Value *NullPtr = Constant::getNullValue(CI->getType());
+
+ if (LenC) {
+ if (LenC->isZero())
+ // Fold memrchr(x, y, 0) --> null.
+ return NullPtr;
+
+ if (LenC->isOne()) {
+ // Fold memrchr(x, y, 1) --> *x == y ? x : null for any x and y,
+ // constant or otherwise.
+ Value *Val = B.CreateLoad(B.getInt8Ty(), SrcStr, "memrchr.char0");
+ // Slice off the character's high end bits.
+ CharVal = B.CreateTrunc(CharVal, B.getInt8Ty());
+ Value *Cmp = B.CreateICmpEQ(Val, CharVal, "memrchr.char0cmp");
+ return B.CreateSelect(Cmp, SrcStr, NullPtr, "memrchr.sel");
+ }
+ }
+
+ StringRef Str;
+ if (!getConstantStringInfo(SrcStr, Str, 0, /*TrimAtNul=*/false))
+ return nullptr;
+
+ uint64_t EndOff = UINT64_MAX;
+ if (LenC) {
+ EndOff = LenC->getZExtValue();
+ if (Str.size() < EndOff)
+ // Punt out-of-bounds accesses to sanitizers and/or libc.
+ return nullptr;
+ }
+
return nullptr;
}
diff --git a/llvm/test/Transforms/InstCombine/memrchr-2.ll b/llvm/test/Transforms/InstCombine/memrchr-2.ll
index d853ec9dc05c9..e1f8e1209c6a2 100644
--- a/llvm/test/Transforms/InstCombine/memrchr-2.ll
+++ b/llvm/test/Transforms/InstCombine/memrchr-2.ll
@@ -1,7 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
;
-; Verify that memrchr calls with an out of bounds size are folded to null.
+; Verify that memrchr calls with an out of bounds size are not folded to
+; null (they might be intercepted by sanitizers).
declare i8* @memrchr(i8*, i32, i64)
@@ -10,15 +11,14 @@ declare i8* @memrchr(i8*, i32, i64)
@a12345 = constant [5 x i8] c"\01\02\03\04\05"
-; Fold memrchr(a12345, C, UINT32_MAX + 1LU) to null (and not to a12345
-; as might happen if the size were to be truncated to int32_t).
+; Do not fold memrchr(a12345, C, UINT32_MAX + 1LU) to null or to a12345
+; as might happen if the size were to be truncated to int32_t.
-define i8* @fold_memrchr_a12345_c_ui32max_p1(i32 %C) {
-; CHECK-LABEL: @fold_memrchr_a12345_c_ui32max_p1(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 [[TMP0:%.*]], i64 4294967296)
+define i8* @call_memrchr_a12345_c_ui32max_p1(i32 %C) {
+; CHECK-LABEL: @call_memrchr_a12345_c_ui32max_p1(
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(4294967296) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 [[TMP0:%.*]], i64 4294967296)
; CHECK-NEXT: ret i8* [[RET]]
;
-; CHECK : ret i8* null
%ptr = getelementptr [5 x i8], [5 x i8]* @a12345, i64 0, i64 0
%ret = call i8* @memrchr(i8* %ptr, i32 %C, i64 4294967296)
@@ -26,14 +26,13 @@ define i8* @fold_memrchr_a12345_c_ui32max_p1(i32 %C) {
}
-; Fold memrchr(ax1, C, UINT32_MAX + 2LU) to null (and not to *ax1 == 1).
+; Do not fold memrchr(ax1, C, UINT32_MAX + 2LU) to null or to *ax1 == 1.
-define i8* @fold_memrchr_ax1_1_ui32max_p2(i32 %C) {
-; CHECK-LABEL: @fold_memrchr_ax1_1_ui32max_p2(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([1 x i8], [1 x i8]* @ax1, i64 0, i64 0), i32 [[TMP0:%.*]], i64 4294967297)
+define i8* @call_memrchr_ax1_c_ui32max_p2(i32 %C) {
+; CHECK-LABEL: @call_memrchr_ax1_c_ui32max_p2(
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(4294967297) getelementptr inbounds ([1 x i8], [1 x i8]* @ax1, i64 0, i64 0), i32 [[TMP0:%.*]], i64 4294967297)
; CHECK-NEXT: ret i8* [[RET]]
;
-; CHECK : ret i8* null
%ptr = getelementptr [1 x i8], [1 x i8]* @ax1, i64 0, i64 0
%ret = call i8* @memrchr(i8* %ptr, i32 %C, i64 4294967297)
@@ -41,28 +40,27 @@ define i8* @fold_memrchr_ax1_1_ui32max_p2(i32 %C) {
}
-; But don't fold memrchr(ax, C, UINT32_MAX + 2LU) to *ax == 1.
+; Do not fold memrchr(ax, C, UINT32_MAX + 2LU) to *ax == 1.
-define i8* @fold_memrchr_ax_1_ui32max_p2(i32 %C) {
-; CHECK-LABEL: @fold_memrchr_ax_1_ui32max_p2(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 [[TMP0:%.*]], i64 4294967297)
+define i8* @call_memrchr_ax_c_ui32max_p2(i32 %C) {
+; CHECK-LABEL: @call_memrchr_ax_c_ui32max_p2(
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(4294967297) getelementptr inbounds ([0 x i8], [0 x i8]* @ax, i64 0, i64 0), i32 [[TMP0:%.*]], i64 4294967297)
; CHECK-NEXT: ret i8* [[RET]]
;
- %ptr = getelementptr [5 x i8], [5 x i8]* @a12345, i64 0, i64 0
+ %ptr = getelementptr [0 x i8], [0 x i8]* @ax, i64 0, i64 0
%ret = call i8* @memrchr(i8* %ptr, i32 %C, i64 4294967297)
ret i8* %ret
}
-; Fold memrchr(a12345, C, 6) to null.
+; Do not fold memrchr(a12345, C, 6) to null.
-define i8* @fold_memrchr_a12345_c_6(i32 %C) {
-; CHECK-LABEL: @fold_memrchr_a12345_c_6(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 [[TMP0:%.*]], i64 6)
+define i8* @call_memrchr_a12345_c_6(i32 %C) {
+; CHECK-LABEL: @call_memrchr_a12345_c_6(
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(6) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 [[TMP0:%.*]], i64 6)
; CHECK-NEXT: ret i8* [[RET]]
;
-; CHECK : ret i8* null
%ptr = getelementptr [5 x i8], [5 x i8]* @a12345, i64 0, i64 0
%ret = call i8* @memrchr(i8* %ptr, i32 %C, i64 6)
@@ -70,14 +68,13 @@ define i8* @fold_memrchr_a12345_c_6(i32 %C) {
}
-; Fold memrchr(a12345, C, SIZE_MAX) to null.
+; Do not fold memrchr(a12345, C, SIZE_MAX) to null.
-define i8* @fold_memrchr_a12345_c_szmax(i32 %C) {
-; CHECK-LABEL: @fold_memrchr_a12345_c_szmax(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 [[TMP0:%.*]], i64 -1)
+define i8* @call_memrchr_a12345_c_szmax(i32 %C) {
+; CHECK-LABEL: @call_memrchr_a12345_c_szmax(
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(18446744073709551615) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 [[TMP0:%.*]], i64 -1)
; CHECK-NEXT: ret i8* [[RET]]
;
-; CHECK : ret i8* null
%ptr = getelementptr [5 x i8], [5 x i8]* @a12345, i64 0, i64 0
%ret = call i8* @memrchr(i8* %ptr, i32 %C, i64 18446744073709551615)
diff --git a/llvm/test/Transforms/InstCombine/memrchr-3.ll b/llvm/test/Transforms/InstCombine/memrchr-3.ll
index df0b72a581919..f717b9734d18d 100644
--- a/llvm/test/Transforms/InstCombine/memrchr-3.ll
+++ b/llvm/test/Transforms/InstCombine/memrchr-3.ll
@@ -15,8 +15,7 @@ declare i8* @memrchr(i8*, i32, i64)
define i8* @fold_memrchr_ax_c_0(i32 %C) {
; CHECK-LABEL: @fold_memrchr_ax_c_0(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* getelementptr inbounds ([0 x i8], [0 x i8]* @ax, i64 0, i64 0), i32 [[TMP0:%.*]], i64 0)
-; CHECK-NEXT: ret i8* [[RET]]
+; CHECK-NEXT: ret i8* null
;
%ptr = getelementptr [0 x i8], [0 x i8]* @ax, i32 0, i32 0
@@ -29,8 +28,7 @@ define i8* @fold_memrchr_ax_c_0(i32 %C) {
define i8* @fold_memrchr_a12345_3_0() {
; CHECK-LABEL: @fold_memrchr_a12345_3_0(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 3, i64 0)
-; CHECK-NEXT: ret i8* [[RET]]
+; CHECK-NEXT: ret i8* null
;
%ptr = getelementptr [5 x i8], [5 x i8]* @a12345, i32 0, i32 0
@@ -43,8 +41,7 @@ define i8* @fold_memrchr_a12345_3_0() {
define i8* @fold_memrchr_a12345_1_1() {
; CHECK-LABEL: @fold_memrchr_a12345_1_1(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 1, i64 1)
-; CHECK-NEXT: ret i8* [[RET]]
+; CHECK-NEXT: ret i8* getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0)
;
%ptr = getelementptr [5 x i8], [5 x i8]* @a12345, i32 0, i32 0
%ret = call i8* @memrchr(i8* %ptr, i32 1, i64 1)
@@ -56,8 +53,7 @@ define i8* @fold_memrchr_a12345_1_1() {
define i8* @fold_memrchr_a12345_5_1() {
; CHECK-LABEL: @fold_memrchr_a12345_5_1(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 5, i64 1)
-; CHECK-NEXT: ret i8* [[RET]]
+; CHECK-NEXT: ret i8* null
;
%ptr = getelementptr [5 x i8], [5 x i8]* @a12345, i32 0, i32 0
%ret = call i8* @memrchr(i8* %ptr, i32 5, i64 1)
@@ -69,8 +65,7 @@ define i8* @fold_memrchr_a12345_5_1() {
define i8* @fold_memrchr_a123123_1_1() {
; CHECK-LABEL: @fold_memrchr_a123123_1_1(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @a123123, i64 0, i64 0), i32 1, i64 1)
-; CHECK-NEXT: ret i8* [[RET]]
+; CHECK-NEXT: ret i8* getelementptr inbounds ([6 x i8], [6 x i8]* @a123123, i64 0, i64 0)
;
%ptr = getelementptr [6 x i8], [6 x i8]* @a123123, i32 0, i32 0
%ret = call i8* @memrchr(i8* %ptr, i32 1, i64 1)
@@ -82,8 +77,7 @@ define i8* @fold_memrchr_a123123_1_1() {
define i8* @fold_memrchr_a123123_3_1() {
; CHECK-LABEL: @fold_memrchr_a123123_3_1(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @a123123, i64 0, i64 0), i32 3, i64 1)
-; CHECK-NEXT: ret i8* [[RET]]
+; CHECK-NEXT: ret i8* null
;
%ptr = getelementptr [6 x i8], [6 x i8]* @a123123, i32 0, i32 0
%ret = call i8* @memrchr(i8* %ptr, i32 3, i64 1)
@@ -95,8 +89,11 @@ define i8* @fold_memrchr_a123123_3_1() {
define i8* @fold_memrchr_ax_c_1(i32 %C) {
; CHECK-LABEL: @fold_memrchr_ax_c_1(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([0 x i8], [0 x i8]* @ax, i64 0, i64 0), i32 [[TMP0:%.*]], i64 1)
-; CHECK-NEXT: ret i8* [[RET]]
+; CHECK-NEXT: [[MEMRCHR_CHAR0:%.*]] = load i8, i8* getelementptr inbounds ([0 x i8], [0 x i8]* @ax, i64 0, i64 0), align 1
+; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[C:%.*]] to i8
+; CHECK-NEXT: [[MEMRCHR_CHAR0CMP:%.*]] = icmp eq i8 [[MEMRCHR_CHAR0]], [[TMP1]]
+; CHECK-NEXT: [[MEMRCHR_SEL:%.*]] = select i1 [[MEMRCHR_CHAR0CMP]], i8* getelementptr inbounds ([0 x i8], [0 x i8]* @ax, i64 0, i64 0), i8* null
+; CHECK-NEXT: ret i8* [[MEMRCHR_SEL]]
;
%ptr = getelementptr [0 x i8], [0 x i8]* @ax, i32 0, i32 0
%ret = call i8* @memrchr(i8* %ptr, i32 %C, i64 1)
@@ -108,7 +105,7 @@ define i8* @fold_memrchr_ax_c_1(i32 %C) {
define i8* @fold_memrchr_a12345_5_5() {
; CHECK-LABEL: @fold_memrchr_a12345_5_5(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 5, i64 5)
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 5, i64 5)
; CHECK-NEXT: ret i8* [[RET]]
;
@@ -122,7 +119,7 @@ define i8* @fold_memrchr_a12345_5_5() {
define i8* @fold_memrchr_a12345_5_4() {
; CHECK-LABEL: @fold_memrchr_a12345_5_4(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 5, i64 4)
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(4) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 5, i64 4)
; CHECK-NEXT: ret i8* [[RET]]
;
@@ -136,7 +133,7 @@ define i8* @fold_memrchr_a12345_5_4() {
define i8* @fold_memrchr_a12345_4_5() {
; CHECK-LABEL: @fold_memrchr_a12345_4_5(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 4, i64 5)
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 4, i64 5)
; CHECK-NEXT: ret i8* [[RET]]
;
@@ -150,7 +147,7 @@ define i8* @fold_memrchr_a12345_4_5() {
define i8* @fold_memrchr_a12345p1_1_4() {
; CHECK-LABEL: @fold_memrchr_a12345p1_1_4(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 1), i32 5, i64 4)
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(4) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 1), i32 5, i64 4)
; CHECK-NEXT: ret i8* [[RET]]
;
@@ -164,7 +161,7 @@ define i8* @fold_memrchr_a12345p1_1_4() {
define i8* @fold_memrchr_a12345_2_5() {
; CHECK-LABEL: @fold_memrchr_a12345_2_5(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 2, i64 5)
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 2, i64 5)
; CHECK-NEXT: ret i8* [[RET]]
;
@@ -178,7 +175,7 @@ define i8* @fold_memrchr_a12345_2_5() {
define i8* @fold_memrchr_a12345_0_n(i64 %N) {
; CHECK-LABEL: @fold_memrchr_a12345_0_n(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 0, i64 [[TMP0:%.*]])
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @a12345, i64 0, i64 0), i32 0, i64 [[N:%.*]])
; CHECK-NEXT: ret i8* [[RET]]
;
@@ -192,7 +189,7 @@ define i8* @fold_memrchr_a12345_0_n(i64 %N) {
define i8* @fold_memrchr_a123123_3_5() {
; CHECK-LABEL: @fold_memrchr_a123123_3_5(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @a123123, i64 0, i64 0), i32 3, i64 5)
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(5) getelementptr inbounds ([6 x i8], [6 x i8]* @a123123, i64 0, i64 0), i32 3, i64 5)
; CHECK-NEXT: ret i8* [[RET]]
;
@@ -206,7 +203,7 @@ define i8* @fold_memrchr_a123123_3_5() {
define i8* @fold_memrchr_a123123_3_6() {
; CHECK-LABEL: @fold_memrchr_a123123_3_6(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @a123123, i64 0, i64 0), i32 3, i64 6)
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @a123123, i64 0, i64 0), i32 3, i64 6)
; CHECK-NEXT: ret i8* [[RET]]
;
@@ -219,7 +216,7 @@ define i8* @fold_memrchr_a123123_3_6() {
define i8* @fold_memrchr_a123123_2_6() {
; CHECK-LABEL: @fold_memrchr_a123123_2_6(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @a123123, i64 0, i64 0), i32 2, i64 6)
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @a123123, i64 0, i64 0), i32 2, i64 6)
; CHECK-NEXT: ret i8* [[RET]]
;
@@ -232,7 +229,7 @@ define i8* @fold_memrchr_a123123_2_6() {
define i8* @fold_memrchr_a123123_1_6() {
; CHECK-LABEL: @fold_memrchr_a123123_1_6(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @a123123, i64 0, i64 0), i32 1, i64 6)
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @a123123, i64 0, i64 0), i32 1, i64 6)
; CHECK-NEXT: ret i8* [[RET]]
;
@@ -246,7 +243,7 @@ define i8* @fold_memrchr_a123123_1_6() {
define i8* @fold_memrchr_a123123_0_6() {
; CHECK-LABEL: @fold_memrchr_a123123_0_6(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @a123123, i64 0, i64 0), i32 0, i64 6)
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @a123123, i64 0, i64 0), i32 0, i64 6)
; CHECK-NEXT: ret i8* [[RET]]
;
diff --git a/llvm/test/Transforms/InstCombine/memrchr-4.ll b/llvm/test/Transforms/InstCombine/memrchr-4.ll
index f1f5595d457f9..d543d76f2099a 100644
--- a/llvm/test/Transforms/InstCombine/memrchr-4.ll
+++ b/llvm/test/Transforms/InstCombine/memrchr-4.ll
@@ -14,7 +14,7 @@ declare i8* @memrchr(i8*, i32, i64)
define i8* @fold_memrchr_a11111_c_5(i32 %C) {
; CHECK-LABEL: @fold_memrchr_a11111_c_5(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @a11111, i64 0, i64 0), i32 [[TMP0:%.*]], i64 5)
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @a11111, i64 0, i64 0), i32 [[C:%.*]], i64 5)
; CHECK-NEXT: ret i8* [[RET]]
;
@@ -28,7 +28,7 @@ define i8* @fold_memrchr_a11111_c_5(i32 %C) {
define i8* @fold_memrchr_a1110111_c_3(i32 %C) {
; CHECK-LABEL: @fold_memrchr_a1110111_c_3(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @a1110111, i64 0, i64 0), i32 [[TMP0:%.*]], i64 3)
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(3) getelementptr inbounds ([7 x i8], [7 x i8]* @a1110111, i64 0, i64 0), i32 [[C:%.*]], i64 3)
; CHECK-NEXT: ret i8* [[RET]]
;
@@ -42,7 +42,7 @@ define i8* @fold_memrchr_a1110111_c_3(i32 %C) {
define i8* @call_memrchr_a1110111_c_4(i32 %C) {
; CHECK-LABEL: @call_memrchr_a1110111_c_4(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @a1110111, i64 0, i64 0), i32 [[TMP0:%.*]], i64 4)
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(4) getelementptr inbounds ([7 x i8], [7 x i8]* @a1110111, i64 0, i64 0), i32 [[C:%.*]], i64 4)
; CHECK-NEXT: ret i8* [[RET]]
;
@@ -56,7 +56,7 @@ define i8* @call_memrchr_a1110111_c_4(i32 %C) {
define i8* @call_memrchr_a11111_c_7(i32 %C) {
; CHECK-LABEL: @call_memrchr_a11111_c_7(
-; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @a1110111, i64 0, i64 0), i32 [[TMP0:%.*]], i64 7)
+; CHECK-NEXT: [[RET:%.*]] = call i8* @memrchr(i8* noundef nonnull dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @a1110111, i64 0, i64 0), i32 [[C:%.*]], i64 7)
; CHECK-NEXT: ret i8* [[RET]]
;
More information about the llvm-commits
mailing list