Am 29.12.2011 19:52, schrieb Reid Kleckner:> I think Chris is saying that the and is necessary because with your i1 > trunc you're ignoring all of the high bits. The and implements that. > If you don't want this behavior, don't generate the trunc in the > first place and just compare the full width to zero.But if a backend sees trunc from i8 to i1 it should know about the and, therefore I think replacing it by and is not a target independent transformation. I'm not saying the and is wrong, I just think InstCombine is the wrong place if InstCombine is supposed to be target independent (which is my assumption that is possibly wrong). By the way i8 and trunc come from clang as clang represents a bool as i8 in memory. of course it would be a nice feature if I could tell clang to always use i1 for bool, this would also remove the problem. Is this possible? -Jochen
> By the way i8 and trunc come from clang as clang represents a bool as i8> in memory. of course it would > be a nice feature if I could tell clang to always use i1 for bool, this > would also remove the problem. > Is this possible? > > -Jochen#include <stdbool.h> ?
Sure, since that would be a different ABI, you would want to define your own clang target. You probably want this for other reasons anyway (calling conventions). -Chris On Dec 30, 2011, at 6:21 AM, Jochen Wilhelmy <j.wilhelmy at arcor.de> wrote:> Am 29.12.2011 19:52, schrieb Reid Kleckner: >> I think Chris is saying that the and is necessary because with your i1 trunc you're ignoring all of the high bits. The and implements that. If you don't want this behavior, don't generate the trunc in the first place and just compare the full width to zero. > But if a backend sees trunc from i8 to i1 it should know about the and, therefore I think replacing it by and is not > a target independent transformation. I'm not saying the and is wrong, I just think InstCombine is the wrong place > if InstCombine is supposed to be target independent (which is my assumption that is possibly wrong). > By the way i8 and trunc come from clang as clang represents a bool as i8 in memory. of course it would > be a nice feature if I could tell clang to always use i1 for bool, this would also remove the problem. > Is this possible? > > -Jochen >
Clang does treat bools as i1 in the IR output if you include stdbool. I had an issue a while back where I needed a function to return an i1 after compilation, and moving to Clang and including stdbool solved it (and it was Samuel who suggested it then as well, so thanks again :-) ) -Gordon -----Original Message----- From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Samuel Crow Sent: Friday, December 30, 2011 12:34 PM To: Jochen Wilhelmy; Reid Kleckner Cc: llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] InstCombine "pessimizes" trunc i8 to i1?> By the way i8 and trunc come from clang as clang represents a bool as > i8> in memory. of course it would > be a nice feature if I could tell clang to always use i1 for bool, > this would also remove the problem. > Is this possible? > > -Jochen#include <stdbool.h> ? _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev