-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[DAGCombiner] add fold (xor (smin(x, C), C)) and fold (xor (smax(x, C), C)) #155141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
13c0f6d
[DAGCombiner] add fold (xor (smin(x, C), C)) -> select (x < C), xor(x…
Yui5427 b83f0f9
Combining umax umin, smin, smax
Yui5427 841ae7c
Use sd_match
Yui5427 7e1effa
Use m_specific and DL
Yui5427 a3a1b2b
Update llvm/test/CodeGen/AArch64/xor-smin-smax.ll
rez5427 8fe2c39
Use freeze N1
Yui5427 baae52b
remove redundent bracket
Yui5427 9d5885b
Add legal
rez5427 1fe7fd5
remove constant zero tests
rez5427 8793ff3
rename xor-smin-smax to xor-min-max
rez5427 1a44da0
Merge branch 'main' into fold-xor-min-constant
RKSimon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,196 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc < %s -mtriple=aarch64-unknown-unknown -mcpu=cortex-a53 | FileCheck %s | ||
|
||
; Test for DAGCombiner optimization: fold (xor (smin(x, C), C)) -> select (x < C), xor (x, C), 0 | ||
|
||
define i64 @test_smin_neg_one(i64 %a) { | ||
; CHECK-LABEL: test_smin_neg_one: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: cmn x0, #1 | ||
; CHECK-NEXT: csinv x0, xzr, x0, ge | ||
; CHECK-NEXT: ret | ||
%1 = tail call i64 @llvm.smin.i64(i64 %a, i64 -1) | ||
%retval.0 = xor i64 %1, -1 | ||
ret i64 %retval.0 | ||
} | ||
|
||
define i64 @test_smin_constant(i64 %a) { | ||
; CHECK-LABEL: test_smin_constant: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: eor x8, x0, #0x8 | ||
; CHECK-NEXT: cmp x0, #8 | ||
; CHECK-NEXT: csel x0, x8, xzr, lt | ||
; CHECK-NEXT: ret | ||
%1 = tail call i64 @llvm.smin.i64(i64 %a, i64 8) | ||
%retval.0 = xor i64 %1, 8 | ||
ret i64 %retval.0 | ||
} | ||
|
||
; Test for DAGCombiner optimization: fold (xor (smax(x, C), C)) -> select (x > C), xor (x, C), 0 | ||
define i64 @test_smax_neg_one(i64 %a) { | ||
; CHECK-LABEL: test_smax_neg_one: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: mvn x8, x0 | ||
; CHECK-NEXT: bic x0, x8, x0, asr #63 | ||
; CHECK-NEXT: ret | ||
%1 = tail call i64 @llvm.smax.i64(i64 %a, i64 -1) | ||
%retval.0 = xor i64 %1, -1 | ||
ret i64 %retval.0 | ||
} | ||
|
||
define i64 @test_smax_constant(i64 %a) { | ||
; CHECK-LABEL: test_smax_constant: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: eor x8, x0, #0x8 | ||
; CHECK-NEXT: cmp x0, #8 | ||
; CHECK-NEXT: csel x0, x8, xzr, gt | ||
; CHECK-NEXT: ret | ||
%1 = tail call i64 @llvm.smax.i64(i64 %a, i64 8) | ||
%retval.0 = xor i64 %1, 8 | ||
ret i64 %retval.0 | ||
} | ||
|
||
define i64 @test_umin_neg_one(i64 %a) { | ||
; CHECK-LABEL: test_umin_neg_one: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: mvn x0, x0 | ||
; CHECK-NEXT: ret | ||
%1 = tail call i64 @llvm.umin.i64(i64 %a, i64 -1) | ||
%retval.0 = xor i64 %1, -1 | ||
ret i64 %retval.0 | ||
} | ||
|
||
define i64 @test_umin_constant(i64 %a) { | ||
; CHECK-LABEL: test_umin_constant: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: eor x8, x0, #0x8 | ||
; CHECK-NEXT: cmp x0, #8 | ||
; CHECK-NEXT: csel x0, x8, xzr, lo | ||
; CHECK-NEXT: ret | ||
%1 = tail call i64 @llvm.umin.i64(i64 %a, i64 8) | ||
%retval.0 = xor i64 %1, 8 | ||
ret i64 %retval.0 | ||
} | ||
|
||
define i64 @test_umax_neg_one(i64 %a) { | ||
; CHECK-LABEL: test_umax_neg_one: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: mov x0, xzr | ||
; CHECK-NEXT: ret | ||
%1 = tail call i64 @llvm.umax.i64(i64 %a, i64 -1) | ||
%retval.0 = xor i64 %1, -1 | ||
ret i64 %retval.0 | ||
} | ||
|
||
define i64 @test_umax_constant(i64 %a) { | ||
; CHECK-LABEL: test_umax_constant: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: eor x8, x0, #0x8 | ||
; CHECK-NEXT: cmp x0, #8 | ||
; CHECK-NEXT: csel x0, x8, xzr, hi | ||
; CHECK-NEXT: ret | ||
%1 = tail call i64 @llvm.umax.i64(i64 %a, i64 8) | ||
%retval.0 = xor i64 %1, 8 | ||
ret i64 %retval.0 | ||
} | ||
|
||
; Test vector cases | ||
define <4 x i32> @test_smin_vector_neg_one(<4 x i32> %a) { | ||
; CHECK-LABEL: test_smin_vector_neg_one: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: movi v1.2d, #0xffffffffffffffff | ||
; CHECK-NEXT: cmgt v1.4s, v1.4s, v0.4s | ||
; CHECK-NEXT: bic v0.16b, v1.16b, v0.16b | ||
; CHECK-NEXT: ret | ||
%1 = tail call <4 x i32> @llvm.smin.v4i32(<4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>) | ||
%retval.0 = xor <4 x i32> %1, <i32 -1, i32 -1, i32 -1, i32 -1> | ||
ret <4 x i32> %retval.0 | ||
} | ||
|
||
define <4 x i32> @test_smin_vector_constant(<4 x i32> %a) { | ||
; CHECK-LABEL: test_smin_vector_constant: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: movi v1.4s, #8 | ||
; CHECK-NEXT: smin v0.4s, v0.4s, v1.4s | ||
; CHECK-NEXT: eor v0.16b, v0.16b, v1.16b | ||
; CHECK-NEXT: ret | ||
%1 = tail call <4 x i32> @llvm.smin.v4i32(<4 x i32> %a, <4 x i32> <i32 8, i32 8, i32 8, i32 8>) | ||
%retval.0 = xor <4 x i32> %1, <i32 8, i32 8, i32 8, i32 8> | ||
ret <4 x i32> %retval.0 | ||
} | ||
|
||
define <4 x i32> @test_smax_vector_neg_one(<4 x i32> %a) { | ||
; CHECK-LABEL: test_smax_vector_neg_one: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: cmge v1.4s, v0.4s, #0 | ||
; CHECK-NEXT: bic v0.16b, v1.16b, v0.16b | ||
; CHECK-NEXT: ret | ||
%1 = tail call <4 x i32> @llvm.smax.v4i32(<4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>) | ||
%retval.0 = xor <4 x i32> %1, <i32 -1, i32 -1, i32 -1, i32 -1> | ||
ret <4 x i32> %retval.0 | ||
} | ||
|
||
define <4 x i32> @test_smax_vector_constant(<4 x i32> %a) { | ||
; CHECK-LABEL: test_smax_vector_constant: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: movi v1.4s, #8 | ||
; CHECK-NEXT: smax v0.4s, v0.4s, v1.4s | ||
; CHECK-NEXT: eor v0.16b, v0.16b, v1.16b | ||
; CHECK-NEXT: ret | ||
%1 = tail call <4 x i32> @llvm.smax.v4i32(<4 x i32> %a, <4 x i32> <i32 8, i32 8, i32 8, i32 8>) | ||
%retval.0 = xor <4 x i32> %1, <i32 8, i32 8, i32 8, i32 8> | ||
ret <4 x i32> %retval.0 | ||
} | ||
|
||
define <4 x i32> @test_umin_vector_neg_one(<4 x i32> %a) { | ||
; CHECK-LABEL: test_umin_vector_neg_one: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: mvn v0.16b, v0.16b | ||
; CHECK-NEXT: ret | ||
%1 = tail call <4 x i32> @llvm.umin.v4i32(<4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>) | ||
%retval.0 = xor <4 x i32> %1, <i32 -1, i32 -1, i32 -1, i32 -1> | ||
ret <4 x i32> %retval.0 | ||
} | ||
|
||
define <4 x i32> @test_umin_vector_constant(<4 x i32> %a) { | ||
; CHECK-LABEL: test_umin_vector_constant: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: movi v1.4s, #8 | ||
; CHECK-NEXT: umin v0.4s, v0.4s, v1.4s | ||
; CHECK-NEXT: eor v0.16b, v0.16b, v1.16b | ||
; CHECK-NEXT: ret | ||
%1 = tail call <4 x i32> @llvm.umin.v4i32(<4 x i32> %a, <4 x i32> <i32 8, i32 8, i32 8, i32 8>) | ||
%retval.0 = xor <4 x i32> %1, <i32 8, i32 8, i32 8, i32 8> | ||
ret <4 x i32> %retval.0 | ||
} | ||
|
||
define <4 x i32> @test_umax_vector_neg_one(<4 x i32> %a) { | ||
; CHECK-LABEL: test_umax_vector_neg_one: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: movi v0.2d, #0000000000000000 | ||
; CHECK-NEXT: ret | ||
%1 = tail call <4 x i32> @llvm.umax.v4i32(<4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>) | ||
%retval.0 = xor <4 x i32> %1, <i32 -1, i32 -1, i32 -1, i32 -1> | ||
ret <4 x i32> %retval.0 | ||
} | ||
|
||
define <4 x i32> @test_umax_vector_constant(<4 x i32> %a) { | ||
; CHECK-LABEL: test_umax_vector_constant: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: movi v1.4s, #8 | ||
; CHECK-NEXT: umax v0.4s, v0.4s, v1.4s | ||
; CHECK-NEXT: eor v0.16b, v0.16b, v1.16b | ||
; CHECK-NEXT: ret | ||
%1 = tail call <4 x i32> @llvm.umax.v4i32(<4 x i32> %a, <4 x i32> <i32 8, i32 8, i32 8, i32 8>) | ||
%retval.0 = xor <4 x i32> %1, <i32 8, i32 8, i32 8, i32 8> | ||
ret <4 x i32> %retval.0 | ||
} | ||
|
||
declare i64 @llvm.smin.i64(i64, i64) | ||
declare i64 @llvm.smax.i64(i64, i64) | ||
declare i64 @llvm.umin.i64(i64, i64) | ||
declare i64 @llvm.umax.i64(i64, i64) | ||
declare <4 x i32> @llvm.smin.v4i32(<4 x i32>, <4 x i32>) | ||
declare <4 x i32> @llvm.smax.v4i32(<4 x i32>, <4 x i32>) | ||
declare <4 x i32> @llvm.umin.v4i32(<4 x i32>, <4 x i32>) | ||
declare <4 x i32> @llvm.umax.v4i32(<4 x i32>, <4 x i32>) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.