<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="">Hi James,<div class=""><br class=""></div><div class="">I’m not sure what you mean about i16 being illegal? Isn’t it something target specific while this commit change a target-independent behavior? What if I have a target where both i32 and i16 are legal?</div><div class=""><br class=""></div><div class="">My impression was that if you feed two i32 to BUILD_VECTOR you should get a v2i32, and you can’t get a v2i16 if you don’t feed i16 inputs. But if I understood correctly Ahmed’s answer, there are implicit conversions happening with BUILD_VECTOR.</div><div class=""><br class=""></div><div class="">— </div><div class="">Mehdi</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 16, 2015, at 12:41 PM, James Molloy <<a href="mailto:james@jamesmolloy.co.uk" class="">james@jamesmolloy.co.uk</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span 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; float: none; display: inline !important;" class="">Hi Mehdi,</span><br 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;" class=""><br 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;" class=""><span 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; float: none; display: inline !important;" class="">It's not altogether surprising- after type legalisation BUILD_VECTOR can't have any illegal types feeding it, and i16 is illegal. I32 is the smallest legal type.<span class="Apple-converted-space"> </span></span><br 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;" class=""><br 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;" class=""><span 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; float: none; display: inline !important;" class="">Therefore it must be able deal with truncation!</span><br 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;" class=""><br 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;" class=""><span 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; float: none; display: inline !important;" class="">Cheers,</span><br 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;" class=""><br 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;" class=""><span 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; float: none; display: inline !important;" class="">James</span><br 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;" class=""><div class="gmail_quote" 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;">On Thu, 16 Apr 2015 at 20:24, Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" class="">mehdi.amini@apple.com</a>> wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><br class="">> On Apr 16, 2015, at 10:52 AM, Ahmed Bougacha <<a href="mailto:ahmed.bougacha@gmail.com" target="_blank" class="">ahmed.bougacha@gmail.com</a>> wrote:<br class="">><br class="">> On Thu, Apr 16, 2015 at 10:44 AM, Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>> wrote:<br class="">>> Hi Simon,<br class="">>><br class="">>> I have an out-of-tree target broken by this commits, and I have a feeling that the problem is in this change.<br class="">>><br class="">>> I have this node: v2i32 BUILD_VECTOR { i32 = Constant<0>, i32 = undef }<br class="">>> That I try to truncate:<br class="">>> getNode(ISD::TRUNCATE, dl, v2i16, N)<br class="">>><br class="">>> After your change, getNode() returns this node:<br class="">>><br class="">>> N = v2i16 BUILD_VECTOR { i32 = Constant<0>, i32 = undef }<br class="">>><br class="">>> Note that the operands are not truncated, which breaks the DAG type system.<br class="">><br class="">> It does? BUILD_VECTOR can truncate integers, and that's the point of<br class="">> this fix, no?<br class=""><br class="">I didn’t know BUILD_VECTOR had an implicit TRUNCATE. Does it carry only implicit truncate or other conversion as well (EXTEND for instance)?<br class=""><br class="">So we are not allowed to fold naively an EXTRACT_VECTOR_ELEMENT that is fed with a BUILD_VECTOR?<br class="">This does not seem in-line with usual behavior in the DAG and it makes combining more complex.<br class=""><br class=""><br class="">Thanks,<br class=""><br class="">Mehdi<br class=""><br class="">><br class="">> -Ahmed<br class="">><br class="">>> I assume you are relying on FoldConstantArithmetic() to magically convert the constant to the truncated type, however it does not work with undef.<br class="">>><br class="">>> I have the feeling that the proper way requires to wrap every operand with a TRUNCATE before calling getNode, but you may see an alternative?<br class="">>><br class="">>> Thanks,<br class="">>><br class="">>> Mehdi<br class="">>><br class="">>><br class="">>><br class="">>>> On Apr 16, 2015, at 1:21 AM, Simon Pilgrim <<a href="mailto:llvm-dev@redking.me.uk" target="_blank" class="">llvm-dev@redking.me.uk</a>> wrote:<br class="">>>><br class="">>>> Author: rksimon<br class="">>>> Date: Thu Apr 16 03:21:09 2015<br class="">>>> New Revision: 235079<br class="">>>><br class="">>>> URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=235079&view=rev" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=235079&view=rev</a><br class="">>>> Log:<br class="">>>> TRUNCATE constant folding - minor fix for rL233224<br class="">>>><br class="">>>> Fix for test case found by James Molloy - TRUNCATE of constant build vectors can be more simply achieved by simply replacing with a new build vector node with the truncated value type - no need to touch the scalar operands at all.<br class="">>>><br class="">>>> Added:<br class="">>>> llvm/trunk/test/CodeGen/AArch64/fold-constants.ll<br class="">>>> Modified:<br class="">>>> llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp<br class="">>>><br class="">>>> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp<br class="">>>> URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=235079&r1=235078&r2=235079&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=235079&r1=235078&r2=235079&view=diff</a><br class="">>>> ==============================================================================<br class="">>>> --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)<br class="">>>> +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Thu Apr 16 03:21:09 2015<br class="">>>> @@ -2851,13 +2851,16 @@ SDValue SelectionDAG::getNode(unsigned O<br class="">>>> // FIXME: Entirely reasonable to perform folding of other unary<br class="">>>> // operations here as the need arises.<br class="">>>> break;<br class="">>>> + case ISD::TRUNCATE:<br class="">>>> + // Constant build vector truncation can be done with the original scalar<br class="">>>> + // operands but with a new build vector with the truncated value type.<br class="">>>> + return getNode(ISD::BUILD_VECTOR, DL, VT, BV->ops());<br class="">>>> case ISD::FNEG:<br class="">>>> case ISD::FABS:<br class="">>>> case ISD::FCEIL:<br class="">>>> case ISD::FTRUNC:<br class="">>>> case ISD::FFLOOR:<br class="">>>> case ISD::FP_EXTEND:<br class="">>>> - case ISD::TRUNCATE:<br class="">>>> case ISD::UINT_TO_FP:<br class="">>>> case ISD::SINT_TO_FP: {<br class="">>>> // Let the above scalar folding handle the folding of each element.<br class="">>>><br class="">>>> Added: llvm/trunk/test/CodeGen/AArch64/fold-constants.ll<br class="">>>> URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/fold-constants.ll?rev=235079&view=auto" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/fold-constants.ll?rev=235079&view=auto</a><br class="">>>> ==============================================================================<br class="">>>> --- llvm/trunk/test/CodeGen/AArch64/fold-constants.ll (added)<br class="">>>> +++ llvm/trunk/test/CodeGen/AArch64/fold-constants.ll Thu Apr 16 03:21:09 2015<br class="">>>> @@ -0,0 +1,21 @@<br class="">>>> +; RUN: llc -mtriple=aarch64-linux-gnu -o - %s | FileCheck %s<br class="">>>> +<br class="">>>> +define i64 @dotests_616() {<br class="">>>> +; CHECK-LABEL: dotests_616<br class="">>>> +; CHECK: movi d0, #0000000000000000<br class="">>>> +; CHECK-NEXT: umov w8, v0.b[2]<br class="">>>> +; CHECK-NEXT: sbfx w8, w8, #0, #1<br class="">>>> +; CHECK-NEXT: fmov s0, w8<br class="">>>> +; CHECK-NEXT: fmov x0, d0<br class="">>>> +; CHECK-NEXT: ret<br class="">>>> +entry:<br class="">>>> + %0 = bitcast <2 x i64> zeroinitializer to <8 x i16><br class="">>>> + %1 = and <8 x i16> zeroinitializer, %0<br class="">>>> + %2 = icmp ne <8 x i16> %1, zeroinitializer<br class="">>>> + %3 = extractelement <8 x i1> %2, i32 2<br class="">>>> + %vgetq_lane285 = sext i1 %3 to i16<br class="">>>> + %vset_lane = insertelement <4 x i16> undef, i16 %vgetq_lane285, i32 0<br class="">>>> + %4 = bitcast <4 x i16> %vset_lane to <1 x i64><br class="">>>> + %vget_lane = extractelement <1 x i64> %4, i32 0<br class="">>>> + ret i64 %vget_lane<br class="">>>> +}<br class="">>>><br class="">>>><br class="">>>> _______________________________________________<br class="">>>> llvm-commits mailing list<br class="">>>><span class="Apple-converted-space"> </span><a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank" class="">llvm-commits@cs.uiuc.edu</a><br class="">>>><span class="Apple-converted-space"> </span><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class="">>><br class="">>><br class="">>> _______________________________________________<br class="">>> llvm-commits mailing list<br class="">>><span class="Apple-converted-space"> </span><a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank" class="">llvm-commits@cs.uiuc.edu</a><br class="">>><span class="Apple-converted-space"> </span><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank" class="">llvm-commits@cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></blockquote></div></div></blockquote></div><br class=""></div></body></html>