Skip to content

Commit

Permalink
[InstCombine] Regenerate test checks (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniofrighetto committed Nov 30, 2023
1 parent 1d20b00 commit 00a10ef
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 35 deletions.
19 changes: 10 additions & 9 deletions llvm/test/Transforms/InstCombine/add3.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt < %s -passes=instcombine -S | grep inttoptr | count 2

;; Target triple for gep raising case below.
Expand All @@ -7,15 +8,15 @@ target triple = "i686-apple-darwin8"
; PR1795
define void @test2(i32 %.val24) {
EntryBlock:
add i32 %.val24, -12
inttoptr i32 %0 to ptr
store i32 1, ptr %1
add i32 %.val24, -16
inttoptr i32 %2 to ptr
getelementptr i32, ptr %3, i32 1
load i32, ptr %4
tail call i32 @callee( i32 %5 )
ret void
add i32 %.val24, -12
inttoptr i32 %0 to ptr
store i32 1, ptr %1
add i32 %.val24, -16
inttoptr i32 %2 to ptr
getelementptr i32, ptr %3, i32 1
load i32, ptr %4
tail call i32 @callee( i32 %5 )
ret void
}

declare i32 @callee(i32)
11 changes: 6 additions & 5 deletions llvm/test/Transforms/InstCombine/addnegneg.ll
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt < %s -passes=instcombine -S | grep " sub " | count 1
; PR2047

define i32 @l(i32 %a, i32 %b, i32 %c, i32 %d) {
entry:
%b.neg = sub i32 0, %b ; <i32> [#uses=1]
%c.neg = sub i32 0, %c ; <i32> [#uses=1]
%sub4 = add i32 %c.neg, %b.neg ; <i32> [#uses=1]
%sub6 = add i32 %sub4, %d ; <i32> [#uses=1]
ret i32 %sub6
%b.neg = sub i32 0, %b ; <i32> [#uses=1]
%c.neg = sub i32 0, %c ; <i32> [#uses=1]
%sub4 = add i32 %c.neg, %b.neg ; <i32> [#uses=1]
%sub6 = add i32 %sub4, %d ; <i32> [#uses=1]
ret i32 %sub6
}
92 changes: 71 additions & 21 deletions llvm/test/Transforms/InstCombine/allocsize.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
;
; Test that instcombine folds allocsize function calls properly.
Expand All @@ -8,54 +9,79 @@
declare ptr @my_malloc(ptr, i32) allocsize(1)
declare ptr @my_calloc(ptr, ptr, i32, i32) allocsize(2, 3)

; CHECK-LABEL: define void @test_malloc
define void @test_malloc(ptr %p, ptr %r) {
; CHECK-LABEL: define void @test_malloc(
; CHECK-SAME: ptr [[P:%.*]], ptr [[R:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = call dereferenceable_or_null(100) ptr @my_malloc(ptr null, i32 100)
; CHECK-NEXT: store ptr [[TMP1]], ptr [[P]], align 8
; CHECK-NEXT: store i64 100, ptr [[R]], align 8
; CHECK-NEXT: ret void
;
%1 = call ptr @my_malloc(ptr null, i32 100)
store ptr %1, ptr %p, align 8 ; To ensure objectsize isn't killed

%2 = call i64 @llvm.objectsize.i64.p0(ptr %1, i1 false)
; CHECK: store i64 100
store i64 %2, ptr %r, align 8
ret void
}

; CHECK-LABEL: define void @test_calloc
define void @test_calloc(ptr %p, ptr %r) {
; CHECK-LABEL: define void @test_calloc(
; CHECK-SAME: ptr [[P:%.*]], ptr [[R:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = call dereferenceable_or_null(500) ptr @my_calloc(ptr null, ptr null, i32 100, i32 5)
; CHECK-NEXT: store ptr [[TMP1]], ptr [[P]], align 8
; CHECK-NEXT: store i64 500, ptr [[R]], align 8
; CHECK-NEXT: ret void
;
%1 = call ptr @my_calloc(ptr null, ptr null, i32 100, i32 5)
store ptr %1, ptr %p, align 8 ; To ensure objectsize isn't killed

%2 = call i64 @llvm.objectsize.i64.p0(ptr %1, i1 false)
; CHECK: store i64 500
store i64 %2, ptr %r, align 8
ret void
}

; Failure cases with non-constant values...
; CHECK-LABEL: define void @test_malloc_fails
define void @test_malloc_fails(ptr %p, ptr %r, i32 %n) {
; CHECK-LABEL: define void @test_malloc_fails(
; CHECK-SAME: ptr [[P:%.*]], ptr [[R:%.*]], i32 [[N:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = call ptr @my_malloc(ptr null, i32 [[N]])
; CHECK-NEXT: store ptr [[TMP1]], ptr [[P]], align 8
; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.objectsize.i64.p0(ptr [[TMP1]], i1 false, i1 false, i1 false)
; CHECK-NEXT: store i64 [[TMP2]], ptr [[R]], align 8
; CHECK-NEXT: ret void
;
%1 = call ptr @my_malloc(ptr null, i32 %n)
store ptr %1, ptr %p, align 8 ; To ensure objectsize isn't killed

; CHECK: @llvm.objectsize.i64.p0
%2 = call i64 @llvm.objectsize.i64.p0(ptr %1, i1 false)
store i64 %2, ptr %r, align 8
ret void
}

; CHECK-LABEL: define void @test_calloc_fails
define void @test_calloc_fails(ptr %p, ptr %r, i32 %n) {
; CHECK-LABEL: define void @test_calloc_fails(
; CHECK-SAME: ptr [[P:%.*]], ptr [[R:%.*]], i32 [[N:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = call ptr @my_calloc(ptr null, ptr null, i32 [[N]], i32 5)
; CHECK-NEXT: store ptr [[TMP1]], ptr [[P]], align 8
; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.objectsize.i64.p0(ptr [[TMP1]], i1 false, i1 false, i1 false)
; CHECK-NEXT: store i64 [[TMP2]], ptr [[R]], align 8
; CHECK-NEXT: [[TMP3:%.*]] = call ptr @my_calloc(ptr null, ptr null, i32 100, i32 [[N]])
; CHECK-NEXT: store ptr [[TMP3]], ptr [[P]], align 8
; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.objectsize.i64.p0(ptr [[TMP3]], i1 false, i1 false, i1 false)
; CHECK-NEXT: store i64 [[TMP4]], ptr [[R]], align 8
; CHECK-NEXT: ret void
;
%1 = call ptr @my_calloc(ptr null, ptr null, i32 %n, i32 5)
store ptr %1, ptr %p, align 8 ; To ensure objectsize isn't killed

; CHECK: @llvm.objectsize.i64.p0
%2 = call i64 @llvm.objectsize.i64.p0(ptr %1, i1 false)
store i64 %2, ptr %r, align 8


%3 = call ptr @my_calloc(ptr null, ptr null, i32 100, i32 %n)
store ptr %3, ptr %p, align 8 ; To ensure objectsize isn't killed

; CHECK: @llvm.objectsize.i64.p0
%4 = call i64 @llvm.objectsize.i64.p0(ptr %3, i1 false)
store i64 %4, ptr %r, align 8
ret void
Expand All @@ -65,21 +91,28 @@ declare ptr @my_malloc_outofline(ptr, i32) #0
declare ptr @my_calloc_outofline(ptr, ptr, i32, i32) #1

; Verifying that out of line allocsize is parsed correctly
; CHECK-LABEL: define void @test_outofline
define void @test_outofline(ptr %p, ptr %r) {
; CHECK-LABEL: define void @test_outofline(
; CHECK-SAME: ptr [[P:%.*]], ptr [[R:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = call dereferenceable_or_null(100) ptr @my_malloc_outofline(ptr null, i32 100)
; CHECK-NEXT: store ptr [[TMP1]], ptr [[P]], align 8
; CHECK-NEXT: store i64 100, ptr [[R]], align 8
; CHECK-NEXT: [[TMP2:%.*]] = call dereferenceable_or_null(500) ptr @my_calloc_outofline(ptr null, ptr null, i32 100, i32 5)
; CHECK-NEXT: store ptr [[TMP2]], ptr [[P]], align 8
; CHECK-NEXT: store i64 500, ptr [[R]], align 8
; CHECK-NEXT: ret void
;
%1 = call ptr @my_malloc_outofline(ptr null, i32 100)
store ptr %1, ptr %p, align 8 ; To ensure objectsize isn't killed

%2 = call i64 @llvm.objectsize.i64.p0(ptr %1, i1 false)
; CHECK: store i64 100
store i64 %2, ptr %r, align 8


%3 = call ptr @my_calloc_outofline(ptr null, ptr null, i32 100, i32 5)
store ptr %3, ptr %p, align 8 ; To ensure objectsize isn't killed

%4 = call i64 @llvm.objectsize.i64.p0(ptr %3, i1 false)
; CHECK: store i64 500
store i64 %4, ptr %r, align 8
ret void
}
Expand All @@ -88,22 +121,37 @@ declare ptr @my_malloc_i64(ptr, i64) #0
declare ptr @my_tiny_calloc(ptr, ptr, i8, i8) #1
declare ptr @my_varied_calloc(ptr, ptr, i32, i8) #1

; CHECK-LABEL: define void @test_overflow
define void @test_overflow(ptr %p, ptr %r) {

; (2**31 + 1) * 2 > 2**31. So overflow. Yay.
; CHECK-LABEL: define void @test_overflow(
; CHECK-SAME: ptr [[P:%.*]], ptr [[R:%.*]]) {
; CHECK-NEXT: [[BIG_MALLOC:%.*]] = call dereferenceable_or_null(4294967298) ptr @my_calloc(ptr null, ptr null, i32 -2147483647, i32 2)
; CHECK-NEXT: store ptr [[BIG_MALLOC]], ptr [[P]], align 8
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.objectsize.i32.p0(ptr [[BIG_MALLOC]], i1 false, i1 false, i1 false)
; CHECK-NEXT: store i32 [[TMP1]], ptr [[R]], align 4
; CHECK-NEXT: [[BIG_LITTLE_MALLOC:%.*]] = call dereferenceable_or_null(508) ptr @my_tiny_calloc(ptr null, ptr null, i8 127, i8 4)
; CHECK-NEXT: store ptr [[BIG_LITTLE_MALLOC]], ptr [[P]], align 8
; CHECK-NEXT: store i32 508, ptr [[R]], align 4
; CHECK-NEXT: [[BIG_MALLOC_I64:%.*]] = call dereferenceable_or_null(8589934592) ptr @my_malloc_i64(ptr null, i64 8589934592)
; CHECK-NEXT: store ptr [[BIG_MALLOC_I64]], ptr [[P]], align 8
; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.objectsize.i32.p0(ptr [[BIG_MALLOC_I64]], i1 false, i1 false, i1 false)
; CHECK-NEXT: store i32 [[TMP2]], ptr [[R]], align 4
; CHECK-NEXT: store i64 8589934592, ptr [[R]], align 8
; CHECK-NEXT: [[VARIED_CALLOC:%.*]] = call dereferenceable_or_null(5000) ptr @my_varied_calloc(ptr null, ptr null, i32 1000, i8 5)
; CHECK-NEXT: store ptr [[VARIED_CALLOC]], ptr [[P]], align 8
; CHECK-NEXT: store i32 5000, ptr [[R]], align 4
; CHECK-NEXT: ret void
;
%big_malloc = call ptr @my_calloc(ptr null, ptr null, i32 2147483649, i32 2)
store ptr %big_malloc, ptr %p, align 8

; CHECK: @llvm.objectsize
%1 = call i32 @llvm.objectsize.i32.p0(ptr %big_malloc, i1 false)
store i32 %1, ptr %r, align 4


%big_little_malloc = call ptr @my_tiny_calloc(ptr null, ptr null, i8 127, i8 4)
store ptr %big_little_malloc, ptr %p, align 8

; CHECK: store i32 508
%2 = call i32 @llvm.objectsize.i32.p0(ptr %big_little_malloc, i1 false)
store i32 %2, ptr %r, align 4

Expand All @@ -112,36 +160,38 @@ define void @test_overflow(ptr %p, ptr %r) {
%big_malloc_i64 = call ptr @my_malloc_i64(ptr null, i64 8589934592)
store ptr %big_malloc_i64, ptr %p, align 8

; CHECK: @llvm.objectsize
%3 = call i32 @llvm.objectsize.i32.p0(ptr %big_malloc_i64, i1 false)
store i32 %3, ptr %r, align 4


%4 = call i64 @llvm.objectsize.i64.p0(ptr %big_malloc_i64, i1 false)
; CHECK: store i64 8589934592
store i64 %4, ptr %r, align 8


; Just intended to ensure that we properly handle args of different types...
%varied_calloc = call ptr @my_varied_calloc(ptr null, ptr null, i32 1000, i8 5)
store ptr %varied_calloc, ptr %p, align 8

; CHECK: store i32 5000
%5 = call i32 @llvm.objectsize.i32.p0(ptr %varied_calloc, i1 false)
store i32 %5, ptr %r, align 4

ret void
}

; CHECK-LABEL: define void @test_nobuiltin
; We had a bug where `nobuiltin` would cause `allocsize` to be ignored in
; @llvm.objectsize calculations.
define void @test_nobuiltin(ptr %p, ptr %r) {
; CHECK-LABEL: define void @test_nobuiltin(
; CHECK-SAME: ptr [[P:%.*]], ptr [[R:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = call dereferenceable_or_null(100) ptr @my_malloc(ptr null, i32 100) #[[ATTR3:[0-9]+]]
; CHECK-NEXT: store ptr [[TMP1]], ptr [[P]], align 8
; CHECK-NEXT: store i64 100, ptr [[R]], align 8
; CHECK-NEXT: ret void
;
%1 = call ptr @my_malloc(ptr null, i32 100) nobuiltin
store ptr %1, ptr %p, align 8

%2 = call i64 @llvm.objectsize.i64.p0(ptr %1, i1 false)
; CHECK: store i64 100
store i64 %2, ptr %r, align 8
ret void
}
Expand Down

0 comments on commit 00a10ef

Please sign in to comment.