-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[InstCombine] Use zext's nneg flag for icmp folding #70845
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
dtcxzyw
merged 16 commits into
llvm:main
from
leo-ard:leo-ard/instcombine-use-nneg-flag-for-icmp-folding
Nov 12, 2023
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
00d0c18
Add NonNeg check for InstCombine
leo-ard ee19789
Add tests for min/max
leo-ard 0fc4460
Regenerate tests
leo-ard 78c4c44
Move test to InstCombine
leo-ard 20612e2
Reformat according to git clang format
leo-ard a3a3082
check with hasNonNeg (comment 2)
leo-ard 5fc1476
change test to instcombine (comment 3)
leo-ard 9d004e1
Moving end-to-end test to PhaseOrdering (comment 3)
leo-ard 77476a6
Fixing failing reg tests
leo-ard 6b044c0
Drop isKnownNonNegative() call
leo-ard 1adba3e
Regenerate min/max test for readability
leo-ard 3f2ad99
Change instcombine icmp folding tests
leo-ard b6f51fe
Remove whitespace at the end of comment lines
leo-ard b6d0007
Update min_max_loop test
leo-ard 67b6990
remove auto-generated note
leo-ard b57b3f8
remove noundef/signext
leo-ard 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
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,111 @@ | ||
; RUN: opt < %s -O3 -S | FileCheck %s | ||
; See issue #55013 and PR #70845 for more details. | ||
; This test comes from the following C program, compiled with clang | ||
; | ||
;; short vecreduce_smin_v2i16(int n, short* v) | ||
;; { | ||
;; short p = 0; | ||
;; for (int i = 0; i < n; ++i) | ||
;; p = p > v[i] ? v[i] : p; | ||
;; return p; | ||
;; } | ||
; | ||
;; short vecreduce_smax_v2i16(int n, short* v) | ||
;; { | ||
;; short p = 0; | ||
;; for (int i = 0; i < n; ++i) | ||
;; p = p < v[i] ? v[i] : p; | ||
;; return p; | ||
;; } | ||
|
||
define i16 @vecreduce_smin_v2i16(i32 %n, ptr %v) { | ||
; CHECK-LABEL: define i16 @vecreduce_smin_v2i16( | ||
; CHECK: @llvm.smin.v2i16 | ||
dtcxzyw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
entry: | ||
br label %for.cond | ||
|
||
for.cond: ; preds = %for.inc, %entry | ||
%p.0 = phi i16 [ 0, %entry ], [ %conv8, %for.inc ] | ||
%i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] | ||
%cmp = icmp slt i32 %i.0, %n | ||
br i1 %cmp, label %for.body, label %for.end | ||
|
||
for.body: ; preds = %for.cond | ||
%conv = sext i16 %p.0 to i32 | ||
%idxprom = sext i32 %i.0 to i64 | ||
%arrayidx = getelementptr inbounds i16, ptr %v, i64 %idxprom | ||
%0 = load i16, ptr %arrayidx, align 2 | ||
%conv1 = sext i16 %0 to i32 | ||
%cmp2 = icmp sgt i32 %conv, %conv1 | ||
br i1 %cmp2, label %cond.true, label %cond.false | ||
|
||
cond.true: ; preds = %for.body | ||
%idxprom4 = sext i32 %i.0 to i64 | ||
%arrayidx5 = getelementptr inbounds i16, ptr %v, i64 %idxprom4 | ||
%1 = load i16, ptr %arrayidx5, align 2 | ||
%conv6 = sext i16 %1 to i32 | ||
br label %cond.end | ||
|
||
cond.false: ; preds = %for.body | ||
%conv7 = sext i16 %p.0 to i32 | ||
br label %cond.end | ||
|
||
cond.end: ; preds = %cond.false, %cond.true | ||
%cond = phi i32 [ %conv6, %cond.true ], [ %conv7, %cond.false ] | ||
%conv8 = trunc i32 %cond to i16 | ||
br label %for.inc | ||
|
||
for.inc: ; preds = %cond.end | ||
%inc = add nsw i32 %i.0, 1 | ||
br label %for.cond | ||
|
||
for.end: ; preds = %for.cond | ||
ret i16 %p.0 | ||
} | ||
|
||
define i16 @vecreduce_smax_v2i16(i32 %n, ptr %v) { | ||
; CHECK-LABEL: define i16 @vecreduce_smax_v2i16( | ||
; CHECK: @llvm.smax.v2i16 | ||
|
||
entry: | ||
br label %for.cond | ||
|
||
for.cond: ; preds = %for.inc, %entry | ||
%p.0 = phi i16 [ 0, %entry ], [ %conv8, %for.inc ] | ||
%i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] | ||
%cmp = icmp slt i32 %i.0, %n | ||
br i1 %cmp, label %for.body, label %for.end | ||
|
||
for.body: ; preds = %for.cond | ||
%conv = sext i16 %p.0 to i32 | ||
%idxprom = sext i32 %i.0 to i64 | ||
%arrayidx = getelementptr inbounds i16, ptr %v, i64 %idxprom | ||
%0 = load i16, ptr %arrayidx, align 2 | ||
%conv1 = sext i16 %0 to i32 | ||
%cmp2 = icmp slt i32 %conv, %conv1 | ||
br i1 %cmp2, label %cond.true, label %cond.false | ||
|
||
cond.true: ; preds = %for.body | ||
%idxprom4 = sext i32 %i.0 to i64 | ||
%arrayidx5 = getelementptr inbounds i16, ptr %v, i64 %idxprom4 | ||
%1 = load i16, ptr %arrayidx5, align 2 | ||
%conv6 = sext i16 %1 to i32 | ||
br label %cond.end | ||
|
||
cond.false: ; preds = %for.body | ||
%conv7 = sext i16 %p.0 to i32 | ||
br label %cond.end | ||
|
||
cond.end: ; preds = %cond.false, %cond.true | ||
%cond = phi i32 [ %conv6, %cond.true ], [ %conv7, %cond.false ] | ||
%conv8 = trunc i32 %cond to i16 | ||
br label %for.inc | ||
|
||
for.inc: ; preds = %cond.end | ||
%inc = add nsw i32 %i.0, 1 | ||
br label %for.cond | ||
|
||
for.end: ; preds = %for.cond | ||
ret i16 %p.0 | ||
} |
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.