<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 29, 2014, at 5:51 PM, Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" class="">mehdi.amini@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">A more generic question I have is why does the code that handle “target-specific” intrinsic has to be in the middle-end? I am surprise to see all that X86 specific code in the middle-end.</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Why don’t we expose a hook (TargetMachine?) for the different targets to handle their own intrinsics their own way?</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">InstCombine, ConstantFolding, AliasAnalysis, … would fallback to the target to handle non-generic intrinsic. </div></div></blockquote></div><br class=""><div class="">This is what I was getting at when I said that I think there could be a better separation of concerns with respect to the handling of target specific intrinsics, which could move some of their handling into the targets themselves on hooks that can be invoked from generic passes.</div><div class=""><br class=""></div><div class="">As to why we need to optimize them, just consider constant folding.  It’s quite possible for constant-foldable forms of target-specific intrinsics to arise from macros, template expansions, etc.  It’s important that we do that constant folding as early as possible because it can affect later decisions like inlining, loop unrolling, etc.  If we can’t constant fold the target-specific operation until after the middle-end, then we’ve potentially lost out.</div><div class=""><br class=""></div><div class="">—Owen</div><div class=""><br class=""></div></body></html>