2019-09-12 22:12:20 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
|
|
; RUN: opt %s -instcombine -S | FileCheck %s
|
|
|
|
|
|
|
|
declare void @use8(i8)
|
|
|
|
|
|
|
|
declare void @use1(i1)
|
|
|
|
declare void @llvm.assume(i1)
|
|
|
|
|
|
|
|
; Here we don't know that at least one of the values being added is non-zero
|
|
|
|
define i1 @t0_bad(i8 %base, i8 %offset) {
|
|
|
|
; CHECK-LABEL: @t0_bad(
|
|
|
|
; CHECK-NEXT: [[ADJUSTED:%.*]] = add i8 [[BASE:%.*]], [[OFFSET:%.*]]
|
|
|
|
; CHECK-NEXT: call void @use8(i8 [[ADJUSTED]])
|
|
|
|
; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp ne i8 [[ADJUSTED]], 0
|
|
|
|
; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ult i8 [[ADJUSTED]], [[BASE]]
|
|
|
|
; CHECK-NEXT: [[R:%.*]] = and i1 [[NOT_NULL]], [[NO_UNDERFLOW]]
|
|
|
|
; CHECK-NEXT: ret i1 [[R]]
|
|
|
|
;
|
|
|
|
%adjusted = add i8 %base, %offset
|
|
|
|
call void @use8(i8 %adjusted)
|
|
|
|
%not_null = icmp ne i8 %adjusted, 0
|
|
|
|
%no_underflow = icmp ult i8 %adjusted, %base
|
|
|
|
%r = and i1 %not_null, %no_underflow
|
|
|
|
ret i1 %r
|
|
|
|
}
|
|
|
|
|
|
|
|
; Ok, base is non-zero.
|
|
|
|
define i1 @t1(i8 %base, i8 %offset) {
|
|
|
|
; CHECK-LABEL: @t1(
|
|
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[BASE:%.*]], 0
|
|
|
|
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
|
|
|
|
; CHECK-NEXT: [[ADJUSTED:%.*]] = add i8 [[BASE]], [[OFFSET:%.*]]
|
|
|
|
; CHECK-NEXT: call void @use8(i8 [[ADJUSTED]])
|
[InstCombine] (a+b) < a && (a+b) != 0 -> (0-b) < a iff a/b != 0 (PR43259)
Summary:
This is again motivated by D67122 sanitizer check enhancement.
That patch seemingly worsens `-fsanitize=pointer-overflow`
overhead from 25% to 50%, which strongly implies missing folds.
For
```
#include <cassert>
char* test(char& base, signed long offset) {
__builtin_assume(offset < 0);
return &base + offset;
}
```
We produce
https://godbolt.org/z/r40U47
and again those two icmp's can be merged:
```
Name: 0
Pre: C != 0
%adjusted = add i8 %base, C
%not_null = icmp ne i8 %adjusted, 0
%no_underflow = icmp ult i8 %adjusted, %base
%r = and i1 %not_null, %no_underflow
=>
%neg_offset = sub i8 0, C
%r = icmp ugt i8 %base, %neg_offset
```
https://rise4fun.com/Alive/ALap
https://rise4fun.com/Alive/slnN
There are 3 other variants of this pattern,
i believe they all will go into InstSimplify.
https://bugs.llvm.org/show_bug.cgi?id=43259
Reviewers: spatel, xbolva00, nikic
Reviewed By: spatel
Subscribers: efriedma, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67849
llvm-svn: 372768
2019-09-25 00:10:50 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = sub i8 0, [[BASE]]
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], [[OFFSET]]
|
|
|
|
; CHECK-NEXT: ret i1 [[TMP2]]
|
2019-09-12 22:12:20 +08:00
|
|
|
;
|
|
|
|
%cmp = icmp slt i8 %base, 0
|
|
|
|
call void @llvm.assume(i1 %cmp)
|
|
|
|
|
|
|
|
%adjusted = add i8 %base, %offset
|
|
|
|
call void @use8(i8 %adjusted)
|
|
|
|
%not_null = icmp ne i8 %adjusted, 0
|
|
|
|
%no_underflow = icmp ult i8 %adjusted, %base
|
|
|
|
%r = and i1 %not_null, %no_underflow
|
|
|
|
ret i1 %r
|
|
|
|
}
|
|
|
|
|
|
|
|
; Ok, offset is non-zero.
|
|
|
|
define i1 @t2(i8 %base, i8 %offset) {
|
|
|
|
; CHECK-LABEL: @t2(
|
|
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[OFFSET:%.*]], 0
|
|
|
|
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
|
|
|
|
; CHECK-NEXT: [[ADJUSTED:%.*]] = add i8 [[BASE:%.*]], [[OFFSET]]
|
|
|
|
; CHECK-NEXT: call void @use8(i8 [[ADJUSTED]])
|
[InstCombine] (a+b) < a && (a+b) != 0 -> (0-b) < a iff a/b != 0 (PR43259)
Summary:
This is again motivated by D67122 sanitizer check enhancement.
That patch seemingly worsens `-fsanitize=pointer-overflow`
overhead from 25% to 50%, which strongly implies missing folds.
For
```
#include <cassert>
char* test(char& base, signed long offset) {
__builtin_assume(offset < 0);
return &base + offset;
}
```
We produce
https://godbolt.org/z/r40U47
and again those two icmp's can be merged:
```
Name: 0
Pre: C != 0
%adjusted = add i8 %base, C
%not_null = icmp ne i8 %adjusted, 0
%no_underflow = icmp ult i8 %adjusted, %base
%r = and i1 %not_null, %no_underflow
=>
%neg_offset = sub i8 0, C
%r = icmp ugt i8 %base, %neg_offset
```
https://rise4fun.com/Alive/ALap
https://rise4fun.com/Alive/slnN
There are 3 other variants of this pattern,
i believe they all will go into InstSimplify.
https://bugs.llvm.org/show_bug.cgi?id=43259
Reviewers: spatel, xbolva00, nikic
Reviewed By: spatel
Subscribers: efriedma, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67849
llvm-svn: 372768
2019-09-25 00:10:50 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = sub i8 0, [[OFFSET]]
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], [[BASE]]
|
|
|
|
; CHECK-NEXT: ret i1 [[TMP2]]
|
2019-09-12 22:12:20 +08:00
|
|
|
;
|
|
|
|
%cmp = icmp slt i8 %offset, 0
|
|
|
|
call void @llvm.assume(i1 %cmp)
|
|
|
|
|
|
|
|
%adjusted = add i8 %base, %offset
|
|
|
|
call void @use8(i8 %adjusted)
|
|
|
|
%not_null = icmp ne i8 %adjusted, 0
|
|
|
|
%no_underflow = icmp ult i8 %adjusted, %base
|
|
|
|
%r = and i1 %not_null, %no_underflow
|
|
|
|
ret i1 %r
|
|
|
|
}
|
|
|
|
|
|
|
|
; We need to produce extra instruction, so one of icmp's must go away.
|
|
|
|
define i1 @t3_oneuse0(i8 %base, i8 %offset) {
|
|
|
|
; CHECK-LABEL: @t3_oneuse0(
|
|
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[BASE:%.*]], 0
|
|
|
|
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
|
|
|
|
; CHECK-NEXT: [[ADJUSTED:%.*]] = add i8 [[BASE]], [[OFFSET:%.*]]
|
|
|
|
; CHECK-NEXT: call void @use8(i8 [[ADJUSTED]])
|
|
|
|
; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp ne i8 [[ADJUSTED]], 0
|
|
|
|
; CHECK-NEXT: call void @use1(i1 [[NOT_NULL]])
|
[InstCombine] (a+b) < a && (a+b) != 0 -> (0-b) < a iff a/b != 0 (PR43259)
Summary:
This is again motivated by D67122 sanitizer check enhancement.
That patch seemingly worsens `-fsanitize=pointer-overflow`
overhead from 25% to 50%, which strongly implies missing folds.
For
```
#include <cassert>
char* test(char& base, signed long offset) {
__builtin_assume(offset < 0);
return &base + offset;
}
```
We produce
https://godbolt.org/z/r40U47
and again those two icmp's can be merged:
```
Name: 0
Pre: C != 0
%adjusted = add i8 %base, C
%not_null = icmp ne i8 %adjusted, 0
%no_underflow = icmp ult i8 %adjusted, %base
%r = and i1 %not_null, %no_underflow
=>
%neg_offset = sub i8 0, C
%r = icmp ugt i8 %base, %neg_offset
```
https://rise4fun.com/Alive/ALap
https://rise4fun.com/Alive/slnN
There are 3 other variants of this pattern,
i believe they all will go into InstSimplify.
https://bugs.llvm.org/show_bug.cgi?id=43259
Reviewers: spatel, xbolva00, nikic
Reviewed By: spatel
Subscribers: efriedma, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67849
llvm-svn: 372768
2019-09-25 00:10:50 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = sub i8 0, [[BASE]]
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], [[OFFSET]]
|
|
|
|
; CHECK-NEXT: ret i1 [[TMP2]]
|
2019-09-12 22:12:20 +08:00
|
|
|
;
|
|
|
|
%cmp = icmp slt i8 %base, 0
|
|
|
|
call void @llvm.assume(i1 %cmp)
|
|
|
|
|
|
|
|
%adjusted = add i8 %base, %offset
|
|
|
|
call void @use8(i8 %adjusted)
|
|
|
|
%not_null = icmp ne i8 %adjusted, 0
|
|
|
|
call void @use1(i1 %not_null)
|
|
|
|
%no_underflow = icmp ult i8 %adjusted, %base
|
|
|
|
%r = and i1 %not_null, %no_underflow
|
|
|
|
ret i1 %r
|
|
|
|
}
|
|
|
|
define i1 @t4_oneuse1(i8 %base, i8 %offset) {
|
|
|
|
; CHECK-LABEL: @t4_oneuse1(
|
|
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[BASE:%.*]], 0
|
|
|
|
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
|
|
|
|
; CHECK-NEXT: [[ADJUSTED:%.*]] = add i8 [[BASE]], [[OFFSET:%.*]]
|
|
|
|
; CHECK-NEXT: call void @use8(i8 [[ADJUSTED]])
|
|
|
|
; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ult i8 [[ADJUSTED]], [[BASE]]
|
|
|
|
; CHECK-NEXT: call void @use1(i1 [[NO_UNDERFLOW]])
|
[InstCombine] (a+b) < a && (a+b) != 0 -> (0-b) < a iff a/b != 0 (PR43259)
Summary:
This is again motivated by D67122 sanitizer check enhancement.
That patch seemingly worsens `-fsanitize=pointer-overflow`
overhead from 25% to 50%, which strongly implies missing folds.
For
```
#include <cassert>
char* test(char& base, signed long offset) {
__builtin_assume(offset < 0);
return &base + offset;
}
```
We produce
https://godbolt.org/z/r40U47
and again those two icmp's can be merged:
```
Name: 0
Pre: C != 0
%adjusted = add i8 %base, C
%not_null = icmp ne i8 %adjusted, 0
%no_underflow = icmp ult i8 %adjusted, %base
%r = and i1 %not_null, %no_underflow
=>
%neg_offset = sub i8 0, C
%r = icmp ugt i8 %base, %neg_offset
```
https://rise4fun.com/Alive/ALap
https://rise4fun.com/Alive/slnN
There are 3 other variants of this pattern,
i believe they all will go into InstSimplify.
https://bugs.llvm.org/show_bug.cgi?id=43259
Reviewers: spatel, xbolva00, nikic
Reviewed By: spatel
Subscribers: efriedma, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67849
llvm-svn: 372768
2019-09-25 00:10:50 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = sub i8 0, [[BASE]]
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], [[OFFSET]]
|
|
|
|
; CHECK-NEXT: ret i1 [[TMP2]]
|
2019-09-12 22:12:20 +08:00
|
|
|
;
|
|
|
|
%cmp = icmp slt i8 %base, 0
|
|
|
|
call void @llvm.assume(i1 %cmp)
|
|
|
|
|
|
|
|
%adjusted = add i8 %base, %offset
|
|
|
|
call void @use8(i8 %adjusted)
|
|
|
|
%not_null = icmp ne i8 %adjusted, 0
|
|
|
|
%no_underflow = icmp ult i8 %adjusted, %base
|
|
|
|
call void @use1(i1 %no_underflow)
|
|
|
|
%r = and i1 %not_null, %no_underflow
|
|
|
|
ret i1 %r
|
|
|
|
}
|
|
|
|
define i1 @t5_oneuse2_bad(i8 %base, i8 %offset) {
|
|
|
|
; CHECK-LABEL: @t5_oneuse2_bad(
|
|
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[BASE:%.*]], 0
|
|
|
|
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
|
|
|
|
; CHECK-NEXT: [[ADJUSTED:%.*]] = add i8 [[BASE]], [[OFFSET:%.*]]
|
|
|
|
; CHECK-NEXT: call void @use8(i8 [[ADJUSTED]])
|
|
|
|
; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp ne i8 [[ADJUSTED]], 0
|
|
|
|
; CHECK-NEXT: call void @use1(i1 [[NOT_NULL]])
|
|
|
|
; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ult i8 [[ADJUSTED]], [[BASE]]
|
|
|
|
; CHECK-NEXT: call void @use1(i1 [[NO_UNDERFLOW]])
|
|
|
|
; CHECK-NEXT: [[R:%.*]] = and i1 [[NOT_NULL]], [[NO_UNDERFLOW]]
|
|
|
|
; CHECK-NEXT: ret i1 [[R]]
|
|
|
|
;
|
|
|
|
%cmp = icmp slt i8 %base, 0
|
|
|
|
call void @llvm.assume(i1 %cmp)
|
|
|
|
|
|
|
|
%adjusted = add i8 %base, %offset
|
|
|
|
call void @use8(i8 %adjusted)
|
|
|
|
%not_null = icmp ne i8 %adjusted, 0
|
|
|
|
call void @use1(i1 %not_null)
|
|
|
|
%no_underflow = icmp ult i8 %adjusted, %base
|
|
|
|
call void @use1(i1 %no_underflow)
|
|
|
|
%r = and i1 %not_null, %no_underflow
|
|
|
|
ret i1 %r
|
|
|
|
}
|
|
|
|
|
|
|
|
define i1 @t6_commutativity0(i8 %base, i8 %offset) {
|
|
|
|
; CHECK-LABEL: @t6_commutativity0(
|
|
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[BASE:%.*]], 0
|
|
|
|
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
|
|
|
|
; CHECK-NEXT: [[ADJUSTED:%.*]] = add i8 [[BASE]], [[OFFSET:%.*]]
|
|
|
|
; CHECK-NEXT: call void @use8(i8 [[ADJUSTED]])
|
[InstCombine] (a+b) < a && (a+b) != 0 -> (0-b) < a iff a/b != 0 (PR43259)
Summary:
This is again motivated by D67122 sanitizer check enhancement.
That patch seemingly worsens `-fsanitize=pointer-overflow`
overhead from 25% to 50%, which strongly implies missing folds.
For
```
#include <cassert>
char* test(char& base, signed long offset) {
__builtin_assume(offset < 0);
return &base + offset;
}
```
We produce
https://godbolt.org/z/r40U47
and again those two icmp's can be merged:
```
Name: 0
Pre: C != 0
%adjusted = add i8 %base, C
%not_null = icmp ne i8 %adjusted, 0
%no_underflow = icmp ult i8 %adjusted, %base
%r = and i1 %not_null, %no_underflow
=>
%neg_offset = sub i8 0, C
%r = icmp ugt i8 %base, %neg_offset
```
https://rise4fun.com/Alive/ALap
https://rise4fun.com/Alive/slnN
There are 3 other variants of this pattern,
i believe they all will go into InstSimplify.
https://bugs.llvm.org/show_bug.cgi?id=43259
Reviewers: spatel, xbolva00, nikic
Reviewed By: spatel
Subscribers: efriedma, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67849
llvm-svn: 372768
2019-09-25 00:10:50 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = sub i8 0, [[BASE]]
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], [[OFFSET]]
|
|
|
|
; CHECK-NEXT: ret i1 [[TMP2]]
|
2019-09-12 22:12:20 +08:00
|
|
|
;
|
|
|
|
%cmp = icmp slt i8 %base, 0
|
|
|
|
call void @llvm.assume(i1 %cmp)
|
|
|
|
|
|
|
|
%adjusted = add i8 %base, %offset
|
|
|
|
call void @use8(i8 %adjusted)
|
|
|
|
%not_null = icmp ne i8 %adjusted, 0
|
|
|
|
%no_underflow = icmp ult i8 %adjusted, %base
|
|
|
|
%r = and i1 %no_underflow, %not_null ; swapped
|
|
|
|
ret i1 %r
|
|
|
|
}
|
|
|
|
define i1 @t7_commutativity1(i8 %base, i8 %offset) {
|
|
|
|
; CHECK-LABEL: @t7_commutativity1(
|
|
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[BASE:%.*]], 0
|
|
|
|
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
|
|
|
|
; CHECK-NEXT: [[ADJUSTED:%.*]] = add i8 [[BASE]], [[OFFSET:%.*]]
|
|
|
|
; CHECK-NEXT: call void @use8(i8 [[ADJUSTED]])
|
[InstCombine] (a+b) < a && (a+b) != 0 -> (0-b) < a iff a/b != 0 (PR43259)
Summary:
This is again motivated by D67122 sanitizer check enhancement.
That patch seemingly worsens `-fsanitize=pointer-overflow`
overhead from 25% to 50%, which strongly implies missing folds.
For
```
#include <cassert>
char* test(char& base, signed long offset) {
__builtin_assume(offset < 0);
return &base + offset;
}
```
We produce
https://godbolt.org/z/r40U47
and again those two icmp's can be merged:
```
Name: 0
Pre: C != 0
%adjusted = add i8 %base, C
%not_null = icmp ne i8 %adjusted, 0
%no_underflow = icmp ult i8 %adjusted, %base
%r = and i1 %not_null, %no_underflow
=>
%neg_offset = sub i8 0, C
%r = icmp ugt i8 %base, %neg_offset
```
https://rise4fun.com/Alive/ALap
https://rise4fun.com/Alive/slnN
There are 3 other variants of this pattern,
i believe they all will go into InstSimplify.
https://bugs.llvm.org/show_bug.cgi?id=43259
Reviewers: spatel, xbolva00, nikic
Reviewed By: spatel
Subscribers: efriedma, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67849
llvm-svn: 372768
2019-09-25 00:10:50 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = sub i8 0, [[BASE]]
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], [[OFFSET]]
|
|
|
|
; CHECK-NEXT: ret i1 [[TMP2]]
|
2019-09-12 22:12:20 +08:00
|
|
|
;
|
|
|
|
%cmp = icmp slt i8 %base, 0
|
|
|
|
call void @llvm.assume(i1 %cmp)
|
|
|
|
|
|
|
|
%adjusted = add i8 %base, %offset
|
|
|
|
call void @use8(i8 %adjusted)
|
|
|
|
%not_null = icmp ne i8 %adjusted, 0
|
2019-09-21 01:43:46 +08:00
|
|
|
%no_underflow = icmp ugt i8 %base, %adjusted ; swapped
|
2019-09-12 22:12:20 +08:00
|
|
|
%r = and i1 %not_null, %no_underflow
|
|
|
|
ret i1 %r
|
|
|
|
}
|
|
|
|
define i1 @t7_commutativity3(i8 %base, i8 %offset) {
|
|
|
|
; CHECK-LABEL: @t7_commutativity3(
|
|
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[BASE:%.*]], 0
|
|
|
|
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
|
|
|
|
; CHECK-NEXT: [[ADJUSTED:%.*]] = add i8 [[BASE]], [[OFFSET:%.*]]
|
|
|
|
; CHECK-NEXT: call void @use8(i8 [[ADJUSTED]])
|
[InstCombine] (a+b) < a && (a+b) != 0 -> (0-b) < a iff a/b != 0 (PR43259)
Summary:
This is again motivated by D67122 sanitizer check enhancement.
That patch seemingly worsens `-fsanitize=pointer-overflow`
overhead from 25% to 50%, which strongly implies missing folds.
For
```
#include <cassert>
char* test(char& base, signed long offset) {
__builtin_assume(offset < 0);
return &base + offset;
}
```
We produce
https://godbolt.org/z/r40U47
and again those two icmp's can be merged:
```
Name: 0
Pre: C != 0
%adjusted = add i8 %base, C
%not_null = icmp ne i8 %adjusted, 0
%no_underflow = icmp ult i8 %adjusted, %base
%r = and i1 %not_null, %no_underflow
=>
%neg_offset = sub i8 0, C
%r = icmp ugt i8 %base, %neg_offset
```
https://rise4fun.com/Alive/ALap
https://rise4fun.com/Alive/slnN
There are 3 other variants of this pattern,
i believe they all will go into InstSimplify.
https://bugs.llvm.org/show_bug.cgi?id=43259
Reviewers: spatel, xbolva00, nikic
Reviewed By: spatel
Subscribers: efriedma, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67849
llvm-svn: 372768
2019-09-25 00:10:50 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = sub i8 0, [[BASE]]
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], [[OFFSET]]
|
|
|
|
; CHECK-NEXT: ret i1 [[TMP2]]
|
2019-09-12 22:12:20 +08:00
|
|
|
;
|
|
|
|
%cmp = icmp slt i8 %base, 0
|
|
|
|
call void @llvm.assume(i1 %cmp)
|
|
|
|
|
|
|
|
%adjusted = add i8 %base, %offset
|
|
|
|
call void @use8(i8 %adjusted)
|
|
|
|
%not_null = icmp ne i8 %adjusted, 0
|
2019-09-21 01:43:46 +08:00
|
|
|
%no_underflow = icmp ugt i8 %base, %adjusted ; swapped
|
2019-09-12 22:12:20 +08:00
|
|
|
%r = and i1 %no_underflow, %not_null ; swapped
|
|
|
|
ret i1 %r
|
|
|
|
}
|
|
|
|
|
|
|
|
; We could have the opposite question, did we get null or overflow happened?
|
|
|
|
define i1 @t8(i8 %base, i8 %offset) {
|
|
|
|
; CHECK-LABEL: @t8(
|
|
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[BASE:%.*]], 0
|
|
|
|
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
|
|
|
|
; CHECK-NEXT: [[ADJUSTED:%.*]] = add i8 [[BASE]], [[OFFSET:%.*]]
|
|
|
|
; CHECK-NEXT: call void @use8(i8 [[ADJUSTED]])
|
[InstCombine] (a+b) < a && (a+b) != 0 -> (0-b) < a iff a/b != 0 (PR43259)
Summary:
This is again motivated by D67122 sanitizer check enhancement.
That patch seemingly worsens `-fsanitize=pointer-overflow`
overhead from 25% to 50%, which strongly implies missing folds.
For
```
#include <cassert>
char* test(char& base, signed long offset) {
__builtin_assume(offset < 0);
return &base + offset;
}
```
We produce
https://godbolt.org/z/r40U47
and again those two icmp's can be merged:
```
Name: 0
Pre: C != 0
%adjusted = add i8 %base, C
%not_null = icmp ne i8 %adjusted, 0
%no_underflow = icmp ult i8 %adjusted, %base
%r = and i1 %not_null, %no_underflow
=>
%neg_offset = sub i8 0, C
%r = icmp ugt i8 %base, %neg_offset
```
https://rise4fun.com/Alive/ALap
https://rise4fun.com/Alive/slnN
There are 3 other variants of this pattern,
i believe they all will go into InstSimplify.
https://bugs.llvm.org/show_bug.cgi?id=43259
Reviewers: spatel, xbolva00, nikic
Reviewed By: spatel
Subscribers: efriedma, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67849
llvm-svn: 372768
2019-09-25 00:10:50 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = sub i8 0, [[BASE]]
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = icmp uge i8 [[TMP1]], [[OFFSET]]
|
|
|
|
; CHECK-NEXT: ret i1 [[TMP2]]
|
2019-09-12 22:12:20 +08:00
|
|
|
;
|
|
|
|
%cmp = icmp slt i8 %base, 0
|
|
|
|
call void @llvm.assume(i1 %cmp)
|
|
|
|
|
|
|
|
%adjusted = add i8 %base, %offset
|
|
|
|
call void @use8(i8 %adjusted)
|
|
|
|
%not_null = icmp eq i8 %adjusted, 0
|
|
|
|
%no_underflow = icmp uge i8 %adjusted, %base
|
|
|
|
%r = or i1 %not_null, %no_underflow
|
|
|
|
ret i1 %r
|
|
|
|
}
|
2019-09-20 23:06:47 +08:00
|
|
|
|
|
|
|
; The comparison can be with any of the values being added.
|
|
|
|
define i1 @t9(i8 %base, i8 %offset) {
|
|
|
|
; CHECK-LABEL: @t9(
|
|
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[BASE:%.*]], 0
|
|
|
|
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
|
|
|
|
; CHECK-NEXT: [[ADJUSTED:%.*]] = add i8 [[BASE]], [[OFFSET:%.*]]
|
|
|
|
; CHECK-NEXT: call void @use8(i8 [[ADJUSTED]])
|
[InstCombine] (a+b) < a && (a+b) != 0 -> (0-b) < a iff a/b != 0 (PR43259)
Summary:
This is again motivated by D67122 sanitizer check enhancement.
That patch seemingly worsens `-fsanitize=pointer-overflow`
overhead from 25% to 50%, which strongly implies missing folds.
For
```
#include <cassert>
char* test(char& base, signed long offset) {
__builtin_assume(offset < 0);
return &base + offset;
}
```
We produce
https://godbolt.org/z/r40U47
and again those two icmp's can be merged:
```
Name: 0
Pre: C != 0
%adjusted = add i8 %base, C
%not_null = icmp ne i8 %adjusted, 0
%no_underflow = icmp ult i8 %adjusted, %base
%r = and i1 %not_null, %no_underflow
=>
%neg_offset = sub i8 0, C
%r = icmp ugt i8 %base, %neg_offset
```
https://rise4fun.com/Alive/ALap
https://rise4fun.com/Alive/slnN
There are 3 other variants of this pattern,
i believe they all will go into InstSimplify.
https://bugs.llvm.org/show_bug.cgi?id=43259
Reviewers: spatel, xbolva00, nikic
Reviewed By: spatel
Subscribers: efriedma, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67849
llvm-svn: 372768
2019-09-25 00:10:50 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = sub i8 0, [[BASE]]
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], [[OFFSET]]
|
|
|
|
; CHECK-NEXT: ret i1 [[TMP2]]
|
2019-09-20 23:06:47 +08:00
|
|
|
;
|
|
|
|
%cmp = icmp slt i8 %base, 0
|
|
|
|
call void @llvm.assume(i1 %cmp)
|
|
|
|
|
|
|
|
%adjusted = add i8 %base, %offset
|
|
|
|
call void @use8(i8 %adjusted)
|
|
|
|
%not_null = icmp ne i8 %adjusted, 0
|
|
|
|
%no_underflow = icmp ult i8 %adjusted, %offset
|
|
|
|
%r = and i1 %not_null, %no_underflow
|
|
|
|
ret i1 %r
|
|
|
|
}
|