Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NFC][InstCombine] Add tests for '((X - Y) - Z)' pattern (PR49858)
- Loading branch information
Showing
1 changed file
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | ||
; RUN: opt -instcombine %s -S -o - | FileCheck %s | ||
|
||
; ((X - Y) - Z) --> X - (Y + Z) because we prefer add's. | ||
|
||
declare void @use8(i8) | ||
|
||
; Basic test | ||
define i8 @t0(i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @t0( | ||
; CHECK-NEXT: [[I0:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 [[I0]], [[Z:%.*]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%i0 = sub i8 %x, %y | ||
%r = sub i8 %i0, %z | ||
ret i8 %r | ||
} | ||
|
||
; No flags are propagated | ||
define i8 @t1_flags(i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @t1_flags( | ||
; CHECK-NEXT: [[O0:%.*]] = sub nuw nsw i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[R:%.*]] = sub nuw nsw i8 [[O0]], [[Z:%.*]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%o0 = sub nuw nsw i8 %x, %y | ||
%r = sub nuw nsw i8 %o0, %z | ||
ret i8 %r | ||
} | ||
|
||
; The inner sub must have single use. | ||
define i8 @n2(i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @n2( | ||
; CHECK-NEXT: [[I0:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: call void @use8(i8 [[I0]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 [[I0]], [[Z:%.*]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%i0 = sub i8 %x, %y ; extra use | ||
call void @use8(i8 %i0) | ||
%r = sub i8 %i0, %z | ||
ret i8 %r | ||
} | ||
|
||
; What if some operand is constant? | ||
|
||
define i8 @t3_c0(i8 %y, i8 %z) { | ||
; CHECK-LABEL: @t3_c0( | ||
; CHECK-NEXT: [[I0:%.*]] = sub i8 42, [[Y:%.*]] | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 [[I0]], [[Z:%.*]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%i0 = sub i8 42, %y | ||
%r = sub i8 %i0, %z | ||
ret i8 %r | ||
} | ||
|
||
define i8 @t4_c1(i8 %x, i8 %z) { | ||
; CHECK-LABEL: @t4_c1( | ||
; CHECK-NEXT: [[I0:%.*]] = add i8 [[X:%.*]], -42 | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 [[I0]], [[Z:%.*]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%i0 = sub i8 %x, 42 | ||
%r = sub i8 %i0, %z | ||
ret i8 %r | ||
} | ||
|
||
define i8 @t5_c2(i8 %x, i8 %y) { | ||
; CHECK-LABEL: @t5_c2( | ||
; CHECK-NEXT: [[I0:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[R:%.*]] = add i8 [[I0]], -42 | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%i0 = sub i8 %x, %y | ||
%r = sub i8 %i0, 42 | ||
ret i8 %r | ||
} | ||
|
||
; What if some operand is constant and there was extra use? | ||
|
||
define i8 @t6_c0_extrause(i8 %y, i8 %z) { | ||
; CHECK-LABEL: @t6_c0_extrause( | ||
; CHECK-NEXT: [[I0:%.*]] = sub i8 42, [[Y:%.*]] | ||
; CHECK-NEXT: call void @use8(i8 [[I0]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 [[I0]], [[Z:%.*]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%i0 = sub i8 42, %y | ||
call void @use8(i8 %i0) | ||
%r = sub i8 %i0, %z | ||
ret i8 %r | ||
} | ||
|
||
define i8 @t7_c1_extrause(i8 %x, i8 %z) { | ||
; CHECK-LABEL: @t7_c1_extrause( | ||
; CHECK-NEXT: [[I0:%.*]] = add i8 [[X:%.*]], -42 | ||
; CHECK-NEXT: call void @use8(i8 [[I0]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 [[I0]], [[Z:%.*]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%i0 = sub i8 %x, 42 | ||
call void @use8(i8 %i0) | ||
%r = sub i8 %i0, %z | ||
ret i8 %r | ||
} | ||
|
||
define i8 @t8_c2_extrause(i8 %x, i8 %y) { | ||
; CHECK-LABEL: @t8_c2_extrause( | ||
; CHECK-NEXT: [[I0:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: call void @use8(i8 [[I0]]) | ||
; CHECK-NEXT: [[R:%.*]] = add i8 [[I0]], -42 | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%i0 = sub i8 %x, %y | ||
call void @use8(i8 %i0) | ||
%r = sub i8 %i0, 42 | ||
ret i8 %r | ||
} | ||
|
||
; What if two operands are constants? | ||
|
||
define i8 @t9_c0_c2(i8 %y, i8 %z) { | ||
; CHECK-LABEL: @t9_c0_c2( | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 18, [[Y:%.*]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%i0 = sub i8 42, %y | ||
%r = sub i8 %i0, 24 | ||
ret i8 %r | ||
} | ||
|
||
define i8 @t10_c1_c2(i8 %x, i8 %z) { | ||
; CHECK-LABEL: @t10_c1_c2( | ||
; CHECK-NEXT: [[R:%.*]] = add i8 [[X:%.*]], -66 | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%i0 = sub i8 %x, 42 | ||
%r = sub i8 %i0, 24 | ||
ret i8 %r | ||
} | ||
|
||
; What if two operands are constants and there was extra use? | ||
|
||
define i8 @t11_c0_c2_extrause(i8 %y, i8 %z) { | ||
; CHECK-LABEL: @t11_c0_c2_extrause( | ||
; CHECK-NEXT: [[I0:%.*]] = sub i8 42, [[Y:%.*]] | ||
; CHECK-NEXT: call void @use8(i8 [[I0]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 18, [[Y]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%i0 = sub i8 42, %y | ||
call void @use8(i8 %i0) | ||
%r = sub i8 %i0, 24 | ||
ret i8 %r | ||
} | ||
|
||
define i8 @t12_c1_c2_exrause(i8 %x, i8 %z) { | ||
; CHECK-LABEL: @t12_c1_c2_exrause( | ||
; CHECK-NEXT: [[I0:%.*]] = add i8 [[X:%.*]], -42 | ||
; CHECK-NEXT: call void @use8(i8 [[I0]]) | ||
; CHECK-NEXT: [[R:%.*]] = add i8 [[X]], -66 | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%i0 = sub i8 %x, 42 | ||
call void @use8(i8 %i0) | ||
%r = sub i8 %i0, 24 | ||
ret i8 %r | ||
} |