-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[VPlan] Simplify select !c, x, y -> select c, y, x #147268
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
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -366,12 +366,6 @@ m_Freeze(const Op0_t &Op0) { | |
return m_VPInstruction<Instruction::Freeze>(Op0); | ||
} | ||
|
||
template <typename Op0_t> | ||
inline UnaryVPInstruction_match<Op0_t, VPInstruction::Not> | ||
m_Not(const Op0_t &Op0) { | ||
return m_VPInstruction<VPInstruction::Not>(Op0); | ||
} | ||
|
||
template <typename Op0_t> | ||
inline UnaryVPInstruction_match<Op0_t, VPInstruction::BranchOnCond> | ||
m_BranchOnCond(const Op0_t &Op0) { | ||
|
@@ -491,6 +485,15 @@ m_Select(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) { | |
{Op0, Op1, Op2}); | ||
} | ||
|
||
template <typename Op0_t> | ||
inline match_combine_or<UnaryVPInstruction_match<Op0_t, VPInstruction::Not>, | ||
AllBinaryRecipe_match<int_pred_ty<is_all_ones>, Op0_t, | ||
Instruction::Xor, true>> | ||
m_Not(const Op0_t &Op0) { | ||
return m_CombineOr(m_VPInstruction<VPInstruction::Not>(Op0), | ||
m_c_Binary<Instruction::Xor>(m_AllOnes(), Op0)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps factor out an m_c_Xor? |
||
} | ||
|
||
template <typename Op0_t, typename Op1_t> | ||
inline match_combine_or< | ||
BinaryVPInstruction_match<Op0_t, Op1_t, VPInstruction::LogicalAnd>, | ||
|
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,62 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 5 | ||
; RUN: opt -p loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -S < %s | FileCheck %s | ||
|
||
define void @neg_cond(ptr noalias %p, ptr noalias %q) { | ||
; CHECK-LABEL: define void @neg_cond( | ||
; CHECK-SAME: ptr noalias [[P:%.*]], ptr noalias [[Q:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*]]: | ||
; CHECK-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] | ||
; CHECK: [[VECTOR_PH]]: | ||
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]] | ||
; CHECK: [[VECTOR_BODY]]: | ||
; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] | ||
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr i32, ptr [[P]], i32 [[INDEX]] | ||
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i32, ptr [[TMP0]], i32 0 | ||
; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP1]], align 4 | ||
; CHECK-NEXT: [[TMP3:%.*]] = icmp ne <4 x i32> [[WIDE_LOAD]], splat (i32 42) | ||
; CHECK-NEXT: [[TMP4:%.*]] = select <4 x i1> [[TMP3]], <4 x i32> splat (i32 42), <4 x i32> splat (i32 43) | ||
; CHECK-NEXT: store <4 x i32> [[TMP4]], ptr [[TMP1]], align 4 | ||
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4 | ||
; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[INDEX_NEXT]], 1024 | ||
; CHECK-NEXT: br i1 [[TMP5]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]] | ||
; CHECK: [[MIDDLE_BLOCK]]: | ||
; CHECK-NEXT: br i1 true, label %[[EXIT:.*]], label %[[SCALAR_PH]] | ||
; CHECK: [[SCALAR_PH]]: | ||
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ 1024, %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ] | ||
; CHECK-NEXT: br label %[[LOOP:.*]] | ||
; CHECK: [[LOOP]]: | ||
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ] | ||
; CHECK-NEXT: [[P_GEP:%.*]] = getelementptr i32, ptr [[P]], i32 [[IV]] | ||
; CHECK-NEXT: [[X:%.*]] = load i32, ptr [[P_GEP]], align 4 | ||
; CHECK-NEXT: [[Q_GEP:%.*]] = getelementptr i32, ptr [[Q]], i32 [[IV]] | ||
; CHECK-NEXT: [[Y:%.*]] = load i32, ptr [[Q_GEP]], align 4 | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X]], 42 | ||
; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[CMP]], true | ||
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[NOT]], i32 42, i32 43 | ||
; CHECK-NEXT: store i32 [[SEL]], ptr [[P_GEP]], align 4 | ||
; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1 | ||
; CHECK-NEXT: [[DONE:%.*]] = icmp eq i32 [[IV_NEXT]], 1024 | ||
; CHECK-NEXT: br i1 [[DONE]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP3:![0-9]+]] | ||
; CHECK: [[EXIT]]: | ||
; CHECK-NEXT: ret void | ||
; | ||
entry: | ||
br label %loop | ||
|
||
loop: | ||
%iv = phi i32 [0, %entry], [%iv.next, %loop] | ||
%p.gep = getelementptr i32, ptr %p, i32 %iv | ||
%x = load i32, ptr %p.gep | ||
%q.gep = getelementptr i32, ptr %q, i32 %iv | ||
%y = load i32, ptr %q.gep | ||
%cmp = icmp eq i32 %x, 42 | ||
%not = xor i1 %cmp, 1 | ||
%sel = select i1 %not, i32 42, i32 43 | ||
store i32 %sel, ptr %p.gep | ||
%iv.next = add i32 %iv, 1 | ||
%done = icmp eq i32 %iv.next, 1024 | ||
br i1 %done, label %exit, label %loop | ||
|
||
exit: | ||
ret void | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to canonicalize negation via
xor
toNot
, although it might cause cost-model issues?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I had the same thought, or just to remove VPInstruction::Not entirely. I can explore this in a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done separately, yes. It's probably preferable to keep
VPInstruction::Not
, as it's clearer and doesn't require creating a constant.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I just ran into this, trying to create a constant in VPBuilder is quite tricky since it requires a) access to the VPlan b) inferring the type of the constant to be materialised