-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SILOptimizer] Add ‘llvm.cttz.*’ Intrinsic support to Constant Folding #23720
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
Conversation
rdar://problem/29522851
@swift-ci Please test and merge |
// Undefined | ||
return nullptr; | ||
} | ||
LZ = LHSI.getBitWidth(); |
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.
Can you do an early exit here?
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.
Post commit review. Please fix.
} | ||
LZ = LHSI.getBitWidth(); | ||
} else { | ||
switch (ID) { |
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.
My suggestion: Use an inline constructor:
unsigned LZ = [&] {
...
}();
Also. Do you really think we are going to support more types of intrinsics here? Why not just put in an assert or something like that.
@@ -278,6 +278,44 @@ constantFoldBinaryWithOverflow(BuiltinInst *BI, BuiltinValueKind ID, | |||
ResultsInError); | |||
} | |||
|
|||
static SILValue countZeros(BuiltinInst *BI, llvm::Intrinsic::ID ID) { |
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.
I find this name means nothing and this needs a comment. My suggestion:
/// Constant fold a cttz or ctlz builtin inst of an integer literal. If \p countLeadingZeros is set to true, then we
/// assume \p bi must be ctlz. If false, \p bi must be cttz.
///
/// NOTE: We assert that \p bi is either cttz or ctlz.
static SILValue constantFoldCountLeadingOrTrialingZeroIntrinsic(BuiltinInst *bi, bool countLeadingZeros) {
...
}
/// Count either the leading or trailing zeros.
Also, do you really need the intrinsic id here? Couldn't you just pass in a bool stating which of the two you are handling?
@@ -278,6 +278,44 @@ constantFoldBinaryWithOverflow(BuiltinInst *BI, BuiltinValueKind ID, | |||
ResultsInError); | |||
} | |||
|
|||
static SILValue countZeros(BuiltinInst *BI, llvm::Intrinsic::ID ID) { | |||
assert(BI->getArguments().size() == 2 && "Ctlz should have 2 args."); |
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 is a bad assert message. You are handling both ctlz and cttz.
Another thing. You can make all of this much simpler by using PatternMatch.h. |
rdar://problem/29522851