zhi chen
2015-Apr-11 00:07 UTC
[LLVMdev] How doesn't llvm generate IR for logical negate operation
How can I generate LLVM IR for both logical NEG (!)? For example, if I have Int32Ty a, For the bitwise NEG(~): c = ~a ; I can use the following API from LLVM: BinaryOperator *neg = BinaryOperator::CreateNeg(nbits, "bitwiseNEG", insertBefore); How, if I want to generate logical NEG: c = !a; what should I do for this? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150410/1656e4c7/attachment.html>
Bruce Hoult
2015-Apr-11 00:22 UTC
[LLVMdev] How doesn't llvm generate IR for logical negate operation
LLVM doesn't have a "logical neg" (or "not") operator. That's a C thing. Do a compare against 0 to create an i1 result, then zero extend the i1 to the size of integer result you want. On Sat, Apr 11, 2015 at 12:07 PM, zhi chen <zchenhn at gmail.com> wrote:> How can I generate LLVM IR for both logical NEG (!)? For example, if I > have Int32Ty a, > > For the bitwise NEG(~): > > c = ~a ; > > I can use the following API from LLVM: > > BinaryOperator *neg = BinaryOperator::CreateNeg(nbits, "bitwiseNEG", insertBefore); > > How, if I want to generate logical NEG: > > c = !a; > > what should I do for this? > > Thanks > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150411/a81a72db/attachment.html>
zhi chen
2015-Apr-11 00:29 UTC
[LLVMdev] How doesn't llvm generate IR for logical negate operation
Thanks, Bruce. So, what is the easiest way to check if there is any bit set to 1 in a <N x i1> vector type? I used bitcast instruction to cast it into "iN" first and them compare iN to 0. Do you have a better way to do it? Thanks again. On Fri, Apr 10, 2015 at 5:22 PM, Bruce Hoult <bruce at hoult.org> wrote:> LLVM doesn't have a "logical neg" (or "not") operator. That's a C thing. > Do a compare against 0 to create an i1 result, then zero extend the i1 to > the size of integer result you want. > > > On Sat, Apr 11, 2015 at 12:07 PM, zhi chen <zchenhn at gmail.com> wrote: > >> How can I generate LLVM IR for both logical NEG (!)? For example, if I >> have Int32Ty a, >> >> For the bitwise NEG(~): >> >> c = ~a ; >> >> I can use the following API from LLVM: >> >> BinaryOperator *neg = BinaryOperator::CreateNeg(nbits, "bitwiseNEG", insertBefore); >> >> How, if I want to generate logical NEG: >> >> c = !a; >> >> what should I do for this? >> >> Thanks >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150410/8f0ce264/attachment.html>
Possibly Parallel Threads
- [LLVMdev] How doesn't llvm generate IR for logical negate operation
- [LLVMdev] How doesn't llvm generate IR for logical negate operation
- [LLVMdev] How doesn't llvm generate IR for logical negate operation
- [LLVMdev] Why there is no unary operator in LLVM?
- Retrieving numeric value of instruction operand