-
Notifications
You must be signed in to change notification settings - Fork 14.3k
KnownBits: generalize high-bits of mul to overflows #114211
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9459ba9
ValueTracking/test: cover known bits of mul
artagnon b6b0cfd
KnownBits: refine high-bits of mul in signed case
artagnon 901b6e5
KnownBitsTest: cover in unittests; address review
artagnon 603ec71
KnownBits: address review; more concise
artagnon 04f1601
KnownBits: generalize high-bits of mul to overflows
artagnon ae92a27
KnownBits: fix issues
artagnon 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,143 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt < %s -passes=instcombine -S | FileCheck %s | ||
|
||
define i8 @mul_low_bits_know(i8 %xx, i8 %yy) { | ||
; CHECK-LABEL: define i8 @mul_low_bits_know( | ||
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) { | ||
; CHECK-NEXT: ret i8 0 | ||
; | ||
%x = and i8 %xx, 2 | ||
%y = and i8 %yy, 4 | ||
%mul = mul i8 %x, %y | ||
%r = and i8 %mul, 6 | ||
ret i8 %r | ||
} | ||
|
||
define i8 @mul_low_bits_know2(i8 %xx, i8 %yy) { | ||
; CHECK-LABEL: define i8 @mul_low_bits_know2( | ||
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) { | ||
; CHECK-NEXT: ret i8 0 | ||
; | ||
%x = or i8 %xx, -2 | ||
%y = and i8 %yy, 4 | ||
%mul = mul i8 %x, %y | ||
%r = and i8 %mul, 2 | ||
ret i8 %r | ||
} | ||
|
||
define i8 @mul_low_bits_partially_known(i8 %xx, i8 %yy) { | ||
; CHECK-LABEL: define i8 @mul_low_bits_partially_known( | ||
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) { | ||
; CHECK-NEXT: [[Y:%.*]] = or i8 [[YY]], 2 | ||
; CHECK-NEXT: [[MUL:%.*]] = sub nsw i8 0, [[Y]] | ||
; CHECK-NEXT: [[R:%.*]] = and i8 [[MUL]], 2 | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%x = or i8 %xx, -4 | ||
%x.notsmin = or i8 %x, 3 | ||
%y = or i8 %yy, -2 | ||
%mul = mul i8 %x.notsmin, %y | ||
%r = and i8 %mul, 6 | ||
ret i8 %r | ||
} | ||
|
||
define i8 @mul_low_bits_unknown(i8 %xx, i8 %yy) { | ||
; CHECK-LABEL: define i8 @mul_low_bits_unknown( | ||
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) { | ||
; CHECK-NEXT: [[X:%.*]] = or i8 [[XX]], 4 | ||
; CHECK-NEXT: [[Y:%.*]] = or i8 [[YY]], 6 | ||
; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]] | ||
; CHECK-NEXT: [[R:%.*]] = and i8 [[MUL]], 6 | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%x = or i8 %xx, -4 | ||
%y = or i8 %yy, -2 | ||
%mul = mul i8 %x, %y | ||
%r = and i8 %mul, 6 | ||
ret i8 %r | ||
} | ||
|
||
define i8 @mul_high_bits_know(i8 %xx, i8 %yy) { | ||
; CHECK-LABEL: define i8 @mul_high_bits_know( | ||
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) { | ||
; CHECK-NEXT: ret i8 0 | ||
; | ||
%x = and i8 %xx, 2 | ||
%y = and i8 %yy, 4 | ||
%mul = mul i8 %x, %y | ||
%r = and i8 %mul, 16 | ||
ret i8 %r | ||
} | ||
|
||
define i8 @mul_high_bits_know2(i8 %xx, i8 %yy) { | ||
; CHECK-LABEL: define i8 @mul_high_bits_know2( | ||
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) { | ||
; CHECK-NEXT: ret i8 -16 | ||
; | ||
%x = or i8 %xx, -2 | ||
%y = and i8 %yy, 4 | ||
%y.nonzero = or i8 %y, 1 | ||
%mul = mul i8 %x, %y.nonzero | ||
%r = and i8 %mul, -16 | ||
ret i8 %r | ||
} | ||
|
||
define i8 @mul_high_bits_know3(i8 %xx, i8 %yy) { | ||
; CHECK-LABEL: define i8 @mul_high_bits_know3( | ||
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) { | ||
; CHECK-NEXT: ret i8 0 | ||
; | ||
%x = or i8 %xx, -4 | ||
%y = or i8 %yy, -2 | ||
%mul = mul i8 %x, %y | ||
%r = and i8 %mul, -16 | ||
ret i8 %r | ||
} | ||
|
||
define i8 @mul_high_bits_unknown(i8 %xx, i8 %yy) { | ||
; CHECK-LABEL: define i8 @mul_high_bits_unknown( | ||
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) { | ||
; CHECK-NEXT: [[X:%.*]] = and i8 [[XX]], 2 | ||
; CHECK-NEXT: [[Y:%.*]] = and i8 [[YY]], 4 | ||
; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i8 [[X]], [[Y]] | ||
; CHECK-NEXT: ret i8 [[MUL]] | ||
; | ||
%x = and i8 %xx, 2 | ||
%y = and i8 %yy, 4 | ||
%mul = mul i8 %x, %y | ||
%r = and i8 %mul, 8 | ||
ret i8 %r | ||
} | ||
|
||
define i8 @mul_high_bits_unknown2(i8 %xx, i8 %yy) { | ||
; CHECK-LABEL: define i8 @mul_high_bits_unknown2( | ||
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) { | ||
; CHECK-NEXT: [[X:%.*]] = or i8 [[XX]], -2 | ||
; CHECK-NEXT: [[Y:%.*]] = and i8 [[YY]], 4 | ||
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X]], [[Y]] | ||
; CHECK-NEXT: [[R:%.*]] = and i8 [[MUL]], -16 | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%x = or i8 %xx, -2 | ||
%y = and i8 %yy, 4 | ||
%mul = mul i8 %x, %y | ||
%r = and i8 %mul, -16 | ||
ret i8 %r | ||
} | ||
|
||
; TODO: This can be reduced to zero. | ||
define i8 @mul_high_bits_unknown3(i8 %xx, i8 %yy) { | ||
; CHECK-LABEL: define i8 @mul_high_bits_unknown3( | ||
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) { | ||
; CHECK-NEXT: [[X:%.*]] = or i8 [[XX]], 28 | ||
; CHECK-NEXT: [[Y:%.*]] = or i8 [[YY]], 30 | ||
; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]] | ||
; CHECK-NEXT: [[R:%.*]] = and i8 [[MUL]], 16 | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%x = or i8 %xx, -4 | ||
%y = or i8 %yy, -2 | ||
%mul = mul i8 %x, %y | ||
%r = and i8 %mul, 16 | ||
ret i8 %r | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.