<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:"Yu Gothic";
        panose-1:2 11 4 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@Yu Gothic";
        panose-1:2 11 4 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">It’s probably also better to not try to infer our weird desired behavior. It should probably be controlled by a specific driver directive, like “-fms-extensions-lp64-intrinsics” or something like that. Using a new directive means that nobody
 can accidentally get this behavior if they for some reason do want LLP64 behavior with Windows intrinsics.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Schwieb<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Erik Schwiebert <br>
<b>Sent:</b> Thursday, June 8, 2017 10:29 AM<br>
<b>To:</b> 'Saleem Abdulrasool' <compnerd@compnerd.org>; Duncan P. N. Exon Smith <dexonsmith@apple.com><br>
<b>Cc:</b> Albert Gutowski <agutowski@google.com>; Reid Kleckner <rnk@google.com>; David Majnemer <david.majnemer@gmail.com>; cfe-commits <cfe-commits@lists.llvm.org><br>
<b>Subject:</b> RE: r284060 - Implement MS _BitScan intrinsics<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Yes, we definitely do not want to introduce pointer-type incompatibility warnings. Predicating the behavior change on LP64 vs LLP64 seems better.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">What’s the best way to do that?  Brian and I can hack on clang a bit, but we’re certainly not experts.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Schwieb<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>From:</b> Saleem Abdulrasool [<a href="mailto:compnerd@compnerd.org">mailto:compnerd@compnerd.org</a>]
<br>
<b>Sent:</b> Wednesday, June 7, 2017 7:32 PM<br>
<b>To:</b> Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com">dexonsmith@apple.com</a>><br>
<b>Cc:</b> Albert Gutowski <<a href="mailto:agutowski@google.com">agutowski@google.com</a>>; Reid Kleckner <<a href="mailto:rnk@google.com">rnk@google.com</a>>; David Majnemer <<a href="mailto:david.majnemer@gmail.com">david.majnemer@gmail.com</a>>; cfe-commits
 <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>>; Erik Schwiebert <<a href="mailto:eriksc@microsoft.com">eriksc@microsoft.com</a>><br>
<b>Subject:</b> Re: r284060 - Implement MS _BitScan intrinsics<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">I'm worried about changing this signature all the time.  I suspect that it will cause the following to be emitted for valid code:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">warning: incompatible pointer types passing 'unsigned long *' to parameter of type 'unsigned int *' [-Wincompatible-pointer-types]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Switching the signature on LP64 sounds much better to me.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Wed, Jun 7, 2017 at 2:56 PM, Duncan P. N. Exon Smith via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<p class="MsoNormal">[... excuse the necromancy...]<br>
<br>
Hi Albert (and Reid and David),<br>
<br>
This commit is breaking some uses of -fms-extensions on Apple platforms.  In particular, Brian and Erik (CC'ed) build against a version of the Windows SDK on Apple platforms.  _BitScanReverse is expected to be 32-bit, matching Windows/LLP64, even though long
 is 64-bit on Darwin/LP64.<br>
<br>
One idea we've had for fixing this is to use "int" instead of "long" for these intrinsics, either:<br>
- all the time, or<br>
- when in LP64 mode (e.g., Darwin + -fms-extensions).<br>
<br>
Any other ideas?<br>
<br>
Thanks,<br>
Duncan<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><br>
> On Oct 12, 2016, at 15:01, Albert Gutowski via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Author: agutowski<br>
> Date: Wed Oct 12 17:01:05 2016<br>
> New Revision: 284060<br>
><br>
> URL: <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%3Frev%3D284060%26view%3Drev&data=02%7C01%7Ceriksc%40microsoft.com%7C2a2522c4af134940d62708d4ae16832e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636324859101456322&sdata=uIMEYcgjFKByhB81x%2FX7%2B0Wm3HMK3hURS4yN7AsKbbI%3D&reserved=0" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=284060&view=rev</a><br>
> Log:<br>
> Implement MS _BitScan intrinsics<br>
><br>
> Summary: _BitScan intrinsics (and some others, for example _Interlocked and _bittest) are supposed to work on both ARM and x86. This is an attempt to isolate them, avoiding repeating their code or writing separate function for each builtin.<br>
><br>
> Reviewers: hans, thakis, rnk, majnemer<br>
><br>
> Subscribers: RKSimon, cfe-commits, aemerson<br>
><br>
> Differential Revision: <a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Freviews.llvm.org%2FD25264&data=02%7C01%7Ceriksc%40microsoft.com%7C2a2522c4af134940d62708d4ae16832e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636324859101456322&sdata=Gwet6%2FKOIUgc03VtXdmk%2BTah9VXUrLReutN36lw3caw%3D&reserved=0" target="_blank">
https://reviews.llvm.org/D25264</a><br>
><br>
> Modified:<br>
>    cfe/trunk/include/clang/Basic/BuiltinsARM.def<br>
>    cfe/trunk/include/clang/Basic/BuiltinsX86.def<br>
>    cfe/trunk/include/clang/Basic/BuiltinsX86_64.def<br>
>    cfe/trunk/lib/Basic/Targets.cpp<br>
>    cfe/trunk/lib/CodeGen/CGBuiltin.cpp<br>
>    cfe/trunk/lib/CodeGen/CodeGenFunction.h<br>
>    cfe/trunk/lib/Headers/intrin.h<br>
>    cfe/trunk/test/CodeGen/ms-intrinsics.c<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/BuiltinsARM.def<br>
> URL: <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Finclude%2Fclang%2FBasic%2FBuiltinsARM.def%3Frev%3D284060%26r1%3D284059%26r2%3D284060%26view%3Ddiff&data=02%7C01%7Ceriksc%40microsoft.com%7C2a2522c4af134940d62708d4ae16832e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636324859101456322&sdata=cse0wyDrNGXlbDkfKXjTS3NKWVc01xiwMFfvoBCzAXw%3D&reserved=0" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsARM.def?rev=284060&r1=284059&r2=284060&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Basic/BuiltinsARM.def (original)<br>
> +++ cfe/trunk/include/clang/Basic/BuiltinsARM.def Wed Oct 12 17:01:05 2016<br>
> @@ -18,6 +18,10 @@<br>
> #   define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)<br>
> #endif<br>
><br>
> +#if defined(BUILTIN) && !defined(TARGET_HEADER_BUILTIN)<br>
> +#  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) BUILTIN(ID, TYPE, ATTRS)<br>
> +#endif<br>
> +<br>
> // In libgcc<br>
> BUILTIN(__clear_cache, "vv*v*", "i")<br>
><br>
> @@ -129,5 +133,11 @@ LANGBUILTIN(_MoveFromCoprocessor2, "UiIU<br>
> LANGBUILTIN(_MoveToCoprocessor, "vUiIUiIUiIUiIUiIUi", "", ALL_MS_LANGUAGES)<br>
> LANGBUILTIN(_MoveToCoprocessor2, "vUiIUiIUiIUiIUiIUi", "", ALL_MS_LANGUAGES)<br>
><br>
> +TARGET_HEADER_BUILTIN(_BitScanForward, "UcULi*ULi", "n", "intrin.h", ALL_MS_LANGUAGES, "")<br>
> +TARGET_HEADER_BUILTIN(_BitScanReverse, "UcULi*ULi", "n", "intrin.h", ALL_MS_LANGUAGES, "")<br>
> +TARGET_HEADER_BUILTIN(_BitScanForward64, "UcULi*ULLi", "n", "intrin.h", ALL_MS_LANGUAGES, "")<br>
> +TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcULi*ULLi", "n", "intrin.h", ALL_MS_LANGUAGES, "")<br>
> +<br>
> #undef BUILTIN<br>
> #undef LANGBUILTIN<br>
> +#undef TARGET_HEADER_BUILTIN<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def<br>
> URL: <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Finclude%2Fclang%2FBasic%2FBuiltinsX86.def%3Frev%3D284060%26r1%3D284059%26r2%3D284060%26view%3Ddiff&data=02%7C01%7Ceriksc%40microsoft.com%7C2a2522c4af134940d62708d4ae16832e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636324859101456322&sdata=GkXN7tOyVzhOiBSf7dGELrISc9Nm1NpFz99AQuldYWo%3D&reserved=0" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=284060&r1=284059&r2=284060&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)<br>
> +++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Wed Oct 12 17:01:05 2016<br>
> @@ -2028,6 +2028,10 @@ TARGET_BUILTIN(__builtin_ia32_selectpd_5<br>
> TARGET_BUILTIN(__builtin_ia32_monitorx, "vv*UiUi", "", "mwaitx")<br>
> TARGET_BUILTIN(__builtin_ia32_mwaitx, "vUiUiUi", "", "mwaitx")<br>
><br>
> +// MSVC<br>
> +TARGET_HEADER_BUILTIN(_BitScanForward, "UcULi*ULi", "n", "intrin.h", ALL_MS_LANGUAGES, "")<br>
> +TARGET_HEADER_BUILTIN(_BitScanReverse, "UcULi*ULi", "n", "intrin.h", ALL_MS_LANGUAGES, "")<br>
> +<br>
> TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")<br>
> TARGET_HEADER_BUILTIN(_ReadBarrier,      "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")<br>
> TARGET_HEADER_BUILTIN(_WriteBarrier,     "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/BuiltinsX86_64.def<br>
> URL: <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Finclude%2Fclang%2FBasic%2FBuiltinsX86_64.def%3Frev%3D284060%26r1%3D284059%26r2%3D284060%26view%3Ddiff&data=02%7C01%7Ceriksc%40microsoft.com%7C2a2522c4af134940d62708d4ae16832e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636324859101456322&sdata=8t%2Bp8phv4rnfI5pxyM87UKrqJo1UT%2FTTQ09b5rX6LZ4%3D&reserved=0" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86_64.def?rev=284060&r1=284059&r2=284060&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Basic/BuiltinsX86_64.def (original)<br>
> +++ cfe/trunk/include/clang/Basic/BuiltinsX86_64.def Wed Oct 12 17:01:05 2016<br>
> @@ -22,6 +22,9 @@<br>
> #  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) BUILTIN(ID, TYPE, ATTRS)<br>
> #endif<br>
><br>
> +TARGET_HEADER_BUILTIN(_BitScanForward64, "UcULi*ULLi", "n", "intrin.h", ALL_MS_LANGUAGES, "")<br>
> +TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcULi*ULLi", "n", "intrin.h", ALL_MS_LANGUAGES, "")<br>
> +<br>
> TARGET_HEADER_BUILTIN(__mulh,  "LLiLLiLLi",    "nch", "intrin.h", ALL_MS_LANGUAGES, "")<br>
> TARGET_HEADER_BUILTIN(__umulh, "ULLiULLiULLi", "nch", "intrin.h", ALL_MS_LANGUAGES, "")<br>
> TARGET_HEADER_BUILTIN(_mul128, "LLiLLiLLiLLi*",      "nh",   "intrin.h", ALL_MS_LANGUAGES, "")<br>
><br>
> Modified: cfe/trunk/lib/Basic/Targets.cpp<br>
> URL: <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Flib%2FBasic%2FTargets.cpp%3Frev%3D284060%26r1%3D284059%26r2%3D284060%26view%3Ddiff&data=02%7C01%7Ceriksc%40microsoft.com%7C2a2522c4af134940d62708d4ae16832e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636324859101456322&sdata=4BduCWaMgnMrn8%2BX%2B3%2F0KIPFo8zEZOhqRHO7%2FFtWB9c%3D&reserved=0" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=284060&r1=284059&r2=284060&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Basic/Targets.cpp (original)<br>
> +++ cfe/trunk/lib/Basic/Targets.cpp Wed Oct 12 17:01:05 2016<br>
> @@ -5588,6 +5588,8 @@ const Builtin::Info ARMTargetInfo::Built<br>
>   { #ID, TYPE, ATTRS, nullptr, LANG, nullptr },<br>
> #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) \<br>
>   { #ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr },<br>
> +#define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANGS, FEATURE) \<br>
> +  { #ID, TYPE, ATTRS, HEADER, LANGS, FEATURE },<br>
> #include "clang/Basic/BuiltinsARM.def"<br>
> };<br>
><br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp<br>
> URL: <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Flib%2FCodeGen%2FCGBuiltin.cpp%3Frev%3D284060%26r1%3D284059%26r2%3D284060%26view%3Ddiff&data=02%7C01%7Ceriksc%40microsoft.com%7C2a2522c4af134940d62708d4ae16832e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636324859101456322&sdata=VR5Jgc%2Bp4C9UOC58q9HBq7FW%2BGrM1W8BIWsRKHleWQw%3D&reserved=0" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=284060&r1=284059&r2=284060&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Oct 12 17:01:05 2016<br>
> @@ -2637,6 +2637,68 @@ static Value *EmitTargetArchBuiltinExpr(<br>
>   }<br>
> }<br>
><br>
> +// Many of MSVC builtins are on both x64 and ARM; to avoid repeating code, we<br>
> +// handle them here.<br>
> +enum class CodeGenFunction::MSVCIntrin {<br>
> +  _BitScanForward,<br>
> +  _BitScanReverse<br>
> +};<br>
> +<br>
> +Value *CodeGenFunction::EmitMSVCBuiltinExpr(MSVCIntrin BuiltinID,<br>
> +                                            const CallExpr *E) {<br>
> +  switch (BuiltinID) {<br>
> +  case MSVCIntrin::_BitScanForward:<br>
> +  case MSVCIntrin::_BitScanReverse: {<br>
> +    Value *ArgValue = EmitScalarExpr(E->getArg(1));<br>
> +<br>
> +    llvm::Type *ArgType = ArgValue->getType();<br>
> +    llvm::Type *IndexType =<br>
> +        EmitScalarExpr(E->getArg(0))->getType()->getPointerElementType();<br>
> +    llvm::Type *ResultType = ConvertType(E->getType());<br>
> +<br>
> +    Value *ArgZero = llvm::Constant::getNullValue(ArgType);<br>
> +    Value *ResZero = llvm::Constant::getNullValue(ResultType);<br>
> +    Value *ResOne = llvm::ConstantInt::get(ResultType, 1);<br>
> +<br>
> +    BasicBlock *Begin = Builder.GetInsertBlock();<br>
> +    BasicBlock *End = createBasicBlock("bitscan_end", this->CurFn);<br>
> +    Builder.SetInsertPoint(End);<br>
> +    PHINode *Result = Builder.CreatePHI(ResultType, 2, "bitscan_result");<br>
> +<br>
> +    Builder.SetInsertPoint(Begin);<br>
> +    Value *IsZero = Builder.CreateICmpEQ(ArgValue, ArgZero);<br>
> +    BasicBlock *NotZero = createBasicBlock("bitscan_not_zero", this->CurFn);<br>
> +    Builder.CreateCondBr(IsZero, End, NotZero);<br>
> +    Result->addIncoming(ResZero, Begin);<br>
> +<br>
> +    Builder.SetInsertPoint(NotZero);<br>
> +    Address IndexAddress = EmitPointerWithAlignment(E->getArg(0));<br>
> +<br>
> +    if (BuiltinID == MSVCIntrin::_BitScanForward) {<br>
> +      Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType);<br>
> +      Value *ZeroCount = Builder.CreateCall(F, {ArgValue, Builder.getTrue()});<br>
> +      ZeroCount = Builder.CreateIntCast(ZeroCount, IndexType, false);<br>
> +      Builder.CreateStore(ZeroCount, IndexAddress, false);<br>
> +    } else {<br>
> +      unsigned ArgWidth = cast<llvm::IntegerType>(ArgType)->getBitWidth();<br>
> +      Value *ArgTypeLastIndex = llvm::ConstantInt::get(IndexType, ArgWidth - 1);<br>
> +<br>
> +      Value *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType);<br>
> +      Value *ZeroCount = Builder.CreateCall(F, {ArgValue, Builder.getTrue()});<br>
> +      ZeroCount = Builder.CreateIntCast(ZeroCount, IndexType, false);<br>
> +      Value *Index = Builder.CreateNSWSub(ArgTypeLastIndex, ZeroCount);<br>
> +      Builder.CreateStore(Index, IndexAddress, false);<br>
> +    }<br>
> +    Builder.CreateBr(End);<br>
> +    Result->addIncoming(ResOne, NotZero);<br>
> +<br>
> +    Builder.SetInsertPoint(End);<br>
> +    return Result;<br>
> +  }<br>
> +  }<br>
> +  llvm_unreachable("Incorrect MSVC intrinsic!");<br>
> +}<br>
> +<br>
> Value *CodeGenFunction::EmitTargetBuiltinExpr(unsigned BuiltinID,<br>
>                                               const CallExpr *E) {<br>
>   if (getContext().BuiltinInfo.isAuxBuiltinID(BuiltinID)) {<br>
> @@ -4561,6 +4623,12 @@ Value *CodeGenFunction::EmitARMBuiltinEx<br>
>     return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0],<br>
>                                   Ops[3], Ops[4], Ops[5]});<br>
>   }<br>
> +  case ARM::BI_BitScanForward:<br>
> +  case ARM::BI_BitScanForward64:<br>
> +    return EmitMSVCBuiltinExpr(MSVCIntrin::_BitScanForward, E);<br>
> +  case ARM::BI_BitScanReverse:<br>
> +  case ARM::BI_BitScanReverse64:<br>
> +    return EmitMSVCBuiltinExpr(MSVCIntrin::_BitScanReverse, E);<br>
>   }<br>
><br>
>   // Get the last argument, which specifies the vector type.<br>
> @@ -7623,6 +7691,12 @@ Value *CodeGenFunction::EmitX86BuiltinEx<br>
>     return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,<br>
>                                llvm::SingleThread);<br>
>   }<br>
> +  case X86::BI_BitScanForward:<br>
> +  case X86::BI_BitScanForward64:<br>
> +    return EmitMSVCBuiltinExpr(MSVCIntrin::_BitScanForward, E);<br>
> +  case X86::BI_BitScanReverse:<br>
> +  case X86::BI_BitScanReverse64:<br>
> +    return EmitMSVCBuiltinExpr(MSVCIntrin::_BitScanReverse, E);<br>
>   }<br>
> }<br>
><br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h<br>
> URL: <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Flib%2FCodeGen%2FCodeGenFunction.h%3Frev%3D284060%26r1%3D284059%26r2%3D284060%26view%3Ddiff&data=02%7C01%7Ceriksc%40microsoft.com%7C2a2522c4af134940d62708d4ae16832e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636324859101456322&sdata=wr2agvaXcUk71Lrl3FRJnZzGOB7gy9yRkkFoIAaa1gY%3D&reserved=0" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=284060&r1=284059&r2=284060&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)<br>
> +++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Oct 12 17:01:05 2016<br>
> @@ -2961,6 +2961,12 @@ public:<br>
>   llvm::Value *EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,<br>
>                                           const CallExpr *E);<br>
><br>
> +private:<br>
> +  enum class MSVCIntrin;<br>
> +<br>
> +public:<br>
> +  llvm::Value *EmitMSVCBuiltinExpr(MSVCIntrin BuiltinID, const CallExpr *E);<br>
> +<br>
>   llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);<br>
>   llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);<br>
>   llvm::Value *EmitObjCBoxedExpr(const ObjCBoxedExpr *E);<br>
><br>
> Modified: cfe/trunk/lib/Headers/intrin.h<br>
> URL: <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Flib%2FHeaders%2Fintrin.h%3Frev%3D284060%26r1%3D284059%26r2%3D284060%26view%3Ddiff&data=02%7C01%7Ceriksc%40microsoft.com%7C2a2522c4af134940d62708d4ae16832e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636324859101456322&sdata=wDfn%2BWeW0rZMc%2BltQ8On3qniNRoeApcEzOQqCRL3Kmo%3D&reserved=0" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/intrin.h?rev=284060&r1=284059&r2=284060&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Headers/intrin.h (original)<br>
> +++ cfe/trunk/lib/Headers/intrin.h Wed Oct 12 17:01:05 2016<br>
> @@ -432,20 +432,6 @@ unsigned __int64 _umul128(unsigned __int<br>
> |* Bit Counting and Testing<br>
> \*----------------------------------------------------------------------------*/<br>
> static __inline__ unsigned char __DEFAULT_FN_ATTRS<br>
> -_BitScanForward(unsigned long *_Index, unsigned long _Mask) {<br>
> -  if (!_Mask)<br>
> -    return 0;<br>
> -  *_Index = __builtin_ctzl(_Mask);<br>
> -  return 1;<br>
> -}<br>
> -static __inline__ unsigned char __DEFAULT_FN_ATTRS<br>
> -_BitScanReverse(unsigned long *_Index, unsigned long _Mask) {<br>
> -  if (!_Mask)<br>
> -    return 0;<br>
> -  *_Index = 31 - __builtin_clzl(_Mask);<br>
> -  return 1;<br>
> -}<br>
> -static __inline__ unsigned char __DEFAULT_FN_ATTRS<br>
> _bittest(long const *_BitBase, long _BitPos) {<br>
>   return (*_BitBase >> _BitPos) & 1;<br>
> }<br>
> @@ -491,20 +477,6 @@ _interlockedbittestandset_rel(long volat<br>
> #endif<br>
> #ifdef __x86_64__<br>
> static __inline__ unsigned char __DEFAULT_FN_ATTRS<br>
> -_BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask) {<br>
> -  if (!_Mask)<br>
> -    return 0;<br>
> -  *_Index = __builtin_ctzll(_Mask);<br>
> -  return 1;<br>
> -}<br>
> -static __inline__ unsigned char __DEFAULT_FN_ATTRS<br>
> -_BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask) {<br>
> -  if (!_Mask)<br>
> -    return 0;<br>
> -  *_Index = 63 - __builtin_clzll(_Mask);<br>
> -  return 1;<br>
> -}<br>
> -static __inline__ unsigned char __DEFAULT_FN_ATTRS<br>
> _bittest64(__int64 const *_BitBase, __int64 _BitPos) {<br>
>   return (*_BitBase >> _BitPos) & 1;<br>
> }<br>
><br>
> Modified: cfe/trunk/test/CodeGen/ms-intrinsics.c<br>
> URL: <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Ftest%2FCodeGen%2Fms-intrinsics.c%3Frev%3D284060%26r1%3D284059%26r2%3D284060%26view%3Ddiff&data=02%7C01%7Ceriksc%40microsoft.com%7C2a2522c4af134940d62708d4ae16832e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636324859101456322&sdata=A3LnOO3Wxc%2BqThHP2Rpo8tJr01tKTRzQFwYdoSqs56w%3D&reserved=0" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-intrinsics.c?rev=284060&r1=284059&r2=284060&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/CodeGen/ms-intrinsics.c (original)<br>
> +++ cfe/trunk/test/CodeGen/ms-intrinsics.c Wed Oct 12 17:01:05 2016<br>
> @@ -1,12 +1,12 @@<br>
> // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \<br>
> // RUN:         -triple i686--windows -Oz -emit-llvm %s -o - \<br>
> -// RUN:         | FileCheck %s -check-prefix CHECK -check-prefix CHECK-I386<br>
> +// RUN:         | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-I386<br>
> // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \<br>
> // RUN:         -triple thumbv7--windows -Oz -emit-llvm %s -o - \<br>
> -// RUN:         | FileCheck %s<br>
> +// RUN:         | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM-X64<br>
> // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \<br>
> // RUN:         -triple x86_64--windows -Oz -emit-llvm %s -o - \<br>
> -// RUN:         | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-X64<br>
> +// RUN:         | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-X64 --check-prefix=CHECK-ARM-X64<br>
><br>
> // intrin.h needs size_t, but -ffreestanding prevents us from getting it from<br>
> // stddef.h.  Work around it with this typedef.<br>
> @@ -14,6 +14,68 @@ typedef __SIZE_TYPE__ size_t;<br>
><br>
> #include <intrin.h><br>
><br>
> +unsigned char test_BitScanForward(unsigned long *Index, unsigned long Mask) {<br>
> +  return _BitScanForward(Index, Mask);<br>
> +}<br>
> +// CHECK: define{{.*}}i8 @test_BitScanForward(i32* {{[a-z_ ]*}}%Index, i32 {{[a-z_ ]*}}%Mask){{.*}}{<br>
> +// CHECK:   [[ISNOTZERO:%[a-z0-9._]+]] = icmp eq i32 %Mask, 0<br>
> +// CHECK:   br i1 [[ISNOTZERO]], label %[[END_LABEL:[a-z0-9.]+]], label %[[ISNOTZERO_LABEL:[0-9]+]]<br>
> +// CHECK: ; <label>:[[END_LABEL]]:<br>
> +// CHECK:   [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[0-9]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]<br>
> +// CHECK:   ret i8 [[RESULT]]<br>
> +// CHECK: ; <label>:[[ISNOTZERO_LABEL]]:<br>
> +// CHECK:   [[INDEX:%[0-9]+]] = tail call i32 @llvm.cttz.i32(i32 %Mask, i1 true)<br>
> +// CHECK:   store i32 [[INDEX]], i32* %Index, align 4<br>
> +// CHECK:   br label %[[END_LABEL]]<br>
> +<br>
> +unsigned char test_BitScanReverse(unsigned long *Index, unsigned long Mask) {<br>
> +  return _BitScanReverse(Index, Mask);<br>
> +}<br>
> +// CHECK: define{{.*}}i8 @test_BitScanReverse(i32* {{[a-z_ ]*}}%Index, i32 {{[a-z_ ]*}}%Mask){{.*}}{<br>
> +// CHECK:   [[ISNOTZERO:%[0-9]+]] = icmp eq i32 %Mask, 0<br>
> +// CHECK:   br i1 [[ISNOTZERO]], label %[[END_LABEL:[a-z0-9.]+]], label %[[ISNOTZERO_LABEL:[0-9]+]]<br>
> +// CHECK: ; <label>:[[END_LABEL]]:<br>
> +// CHECK:   [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[0-9]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]<br>
> +// CHECK:   ret i8 [[RESULT]]<br>
> +// CHECK: ; <label>:[[ISNOTZERO_LABEL]]:<br>
> +// CHECK:   [[REVINDEX:%[0-9]+]] = tail call i32 @llvm.ctlz.i32(i32 %Mask, i1 true)<br>
> +// CHECK:   [[INDEX:%[0-9]+]] = xor i32 [[REVINDEX]], 31<br>
> +// CHECK:   store i32 [[INDEX]], i32* %Index, align 4<br>
> +// CHECK:   br label %[[END_LABEL]]<br>
> +<br>
> +#if defined(__x86_64__) || defined(__arm__)<br>
> +unsigned char test_BitScanForward64(unsigned long *Index, unsigned __int64 Mask) {<br>
> +  return _BitScanForward64(Index, Mask);<br>
> +}<br>
> +// CHECK-ARM-X64: define{{.*}}i8 @test_BitScanForward64(i32* {{[a-z_ ]*}}%Index, i64 {{[a-z_ ]*}}%Mask){{.*}}{<br>
> +// CHECK-ARM-X64:   [[ISNOTZERO:%[a-z0-9._]+]] = icmp eq i64 %Mask, 0<br>
> +// CHECK-ARM-X64:   br i1 [[ISNOTZERO]], label %[[END_LABEL:[a-z0-9.]+]], label %[[ISNOTZERO_LABEL:[0-9]+]]<br>
> +// CHECK-ARM-X64: ; <label>:[[END_LABEL]]:<br>
> +// CHECK-ARM-X64:   [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[0-9]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]<br>
> +// CHECK-ARM-X64:   ret i8 [[RESULT]]<br>
> +// CHECK-ARM-X64: ; <label>:[[ISNOTZERO_LABEL]]:<br>
> +// CHECK-ARM-X64:   [[INDEX:%[0-9]+]] = tail call i64 @llvm.cttz.i64(i64 %Mask, i1 true)<br>
> +// CHECK-ARM-X64:   [[TRUNC_INDEX:%[0-9]+]] = trunc i64 [[INDEX]] to i32<br>
> +// CHECK-ARM-X64:   store i32 [[TRUNC_INDEX]], i32* %Index, align 4<br>
> +// CHECK-ARM-X64:   br label %[[END_LABEL]]<br>
> +<br>
> +unsigned char test_BitScanReverse64(unsigned long *Index, unsigned __int64 Mask) {<br>
> +  return _BitScanReverse64(Index, Mask);<br>
> +}<br>
> +// CHECK-ARM-X64: define{{.*}}i8 @test_BitScanReverse64(i32* {{[a-z_ ]*}}%Index, i64 {{[a-z_ ]*}}%Mask){{.*}}{<br>
> +// CHECK-ARM-X64:   [[ISNOTZERO:%[0-9]+]] = icmp eq i64 %Mask, 0<br>
> +// CHECK-ARM-X64:   br i1 [[ISNOTZERO]], label %[[END_LABEL:[a-z0-9.]+]], label %[[ISNOTZERO_LABEL:[0-9]+]]<br>
> +// CHECK-ARM-X64: ; <label>:[[END_LABEL]]:<br>
> +// CHECK-ARM-X64:   [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[0-9]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]<br>
> +// CHECK-ARM-X64:   ret i8 [[RESULT]]<br>
> +// CHECK-ARM-X64: ; <label>:[[ISNOTZERO_LABEL]]:<br>
> +// CHECK-ARM-X64:   [[REVINDEX:%[0-9]+]] = tail call i64 @llvm.ctlz.i64(i64 %Mask, i1 true)<br>
> +// CHECK-ARM-X64:   [[TRUNC_REVINDEX:%[0-9]+]] = trunc i64 [[REVINDEX]] to i32<br>
> +// CHECK-ARM-X64:   [[INDEX:%[0-9]+]] = xor i32 [[TRUNC_REVINDEX]], 63<br>
> +// CHECK-ARM-X64:   store i32 [[INDEX]], i32* %Index, align 4<br>
> +// CHECK-ARM-X64:   br label %[[END_LABEL]]<br>
> +#endif<br>
> +<br>
> void *test_InterlockedExchangePointer(void * volatile *Target, void *Value) {<br>
>   return _InterlockedExchangePointer(Target, Value);<br>
> }<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fcfe-commits&data=02%7C01%7Ceriksc%40microsoft.com%7C2a2522c4af134940d62708d4ae16832e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636324859101456322&sdata=J53dFPlzSTUjgLz2YyI0h3LDD80rWcc3CahkORS1stk%3D&reserved=0" target="_blank">
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fcfe-commits&data=02%7C01%7Ceriksc%40microsoft.com%7C2a2522c4af134940d62708d4ae16832e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636324859101456322&sdata=J53dFPlzSTUjgLz2YyI0h3LDD80rWcc3CahkORS1stk%3D&reserved=0" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">-- <o:p></o:p></p>
<div>
<p class="MsoNormal">Saleem Abdulrasool<br>
compnerd (at) compnerd (dot) org<o:p></o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>