Skip to content

Conversation

@shajrawi
Copy link

@shajrawi shajrawi commented Apr 1, 2019

rdar://problem/29522851

@shajrawi shajrawi requested a review from gottesmm April 1, 2019 23:11
@shajrawi
Copy link
Author

shajrawi commented Apr 1, 2019

@swift-ci Please test and merge

@swift-ci swift-ci merged commit f8e4c75 into swiftlang:master Apr 2, 2019
@shajrawi shajrawi deleted the cttz branch April 2, 2019 05:54
// Undefined
return nullptr;
}
LZ = LHSI.getBitWidth();
Copy link
Contributor

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?

Copy link
Contributor

@gottesmm gottesmm left a 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) {
Copy link
Contributor

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.

ResultsInError);
}

static SILValue countZeros(BuiltinInst *BI, llvm::Intrinsic::ID ID) {
Copy link
Contributor

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?

}

static SILValue countZeros(BuiltinInst *BI, llvm::Intrinsic::ID ID) {
assert(BI->getArguments().size() == 2 && "Ctlz should have 2 args.");
Copy link
Contributor

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.

@gottesmm
Copy link
Contributor

gottesmm commented Apr 2, 2019

Another thing. You can make all of this much simpler by using PatternMatch.h.

@shajrawi
Copy link
Author

shajrawi commented Apr 2, 2019

Thanks @gottesmm - #23739

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants