<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Would we not also want to add a pattern which matches an arithmetic shift of [17..31]?<div><br></div><div>-Jim</div><div><br><div><div>On Jul 5, 2013, at 11:28 AM, Arnold Schwaighofer <<a href="mailto:aschwaighofer@apple.com">aschwaighofer@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="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;">Author: arnolds<br>Date: Fri Jul 5 13:28:39 2013<br>New Revision: 185712<br><br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=185712&view=rev">http://llvm.org/viewvc/llvm-project?rev=185712&view=rev</a><br>Log:<br>ARM: Fix incorrect pack pattern<br><br>A "pkhtb x, x, y asr #num" uses the lower 16 bits of "y asr #num" and packs them<br>in the bottom half of "x". An arithmetic and logic shift are only equivalent in<br>this context if the shift amount is 16. We would be shifting in ones into the<br>bottom 16bits instead of zeros if "y" is negative.<br><br><a href="radar://14338767">radar://14338767</a><br><br>Modified:<br> llvm/trunk/lib/Target/ARM/ARMInstrInfo.td<br> llvm/trunk/test/CodeGen/ARM/pack.ll<br><br>Modified: llvm/trunk/lib/Target/ARM/ARMInstrInfo.td<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMInstrInfo.td?rev=185712&r1=185711&r2=185712&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMInstrInfo.td?rev=185712&r1=185711&r2=185712&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Target/ARM/ARMInstrInfo.td (original)<br>+++ llvm/trunk/lib/Target/ARM/ARMInstrInfo.td Fri Jul 5 13:28:39 2013<br>@@ -4011,9 +4011,11 @@ def PKHTB : APKHI<0b01101000, 1, (outs G<br><br>// Alternate cases for PKHTB where identities eliminate some nodes. Note that<br>// a shift amount of 0 is *not legal* here, it is PKHBT instead.<br>+// We also can not replace a srl (17..31) by an arithmetic shift we would use in<br>+// pkhtb src1, src2, asr (17..31).<br>def : ARMV6Pat<(or (and GPRnopc:$src1, 0xFFFF0000),<br>- (srl GPRnopc:$src2, imm16_31:$sh)),<br>- (PKHTB GPRnopc:$src1, GPRnopc:$src2, imm16_31:$sh)>;<br>+ (srl GPRnopc:$src2, imm16:$sh)),<br>+ (PKHTB GPRnopc:$src1, GPRnopc:$src2, imm16:$sh)>;<br>def : ARMV6Pat<(or (and GPRnopc:$src1, 0xFFFF0000),<br> (and (srl GPRnopc:$src2, imm1_15:$sh), 0xFFFF)),<br> (PKHTB GPRnopc:$src1, GPRnopc:$src2, imm1_15:$sh)>;<br><br>Modified: llvm/trunk/test/CodeGen/ARM/pack.ll<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/pack.ll?rev=185712&r1=185711&r2=185712&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/pack.ll?rev=185712&r1=185711&r2=185712&view=diff</a><br>==============================================================================<br>--- llvm/trunk/test/CodeGen/ARM/pack.ll (original)<br>+++ llvm/trunk/test/CodeGen/ARM/pack.ll Fri Jul 5 13:28:39 2013<br>@@ -78,11 +78,24 @@ define i32 @test7(i32 %X, i32 %Y) {<br><span class="Apple-tab-span" style="white-space: pre;"> </span>ret i32 %tmp57<br>}<br><br>+; Arithmetic and logic right shift does not have the same semantics if shifting<br>+; by more than 16 in this context.<br>+<br>; CHECK: test8<br>-; CHECK: pkhtb r0, r0, r1, asr #22<br>+; CHECK-NOT: pkhtb r0, r0, r1, asr #22<br>define i32 @test8(i32 %X, i32 %Y) {<br><span class="Apple-tab-span" style="white-space: pre;"> </span>%tmp1 = and i32 %X, -65536<br><span class="Apple-tab-span" style="white-space: pre;"> </span>%tmp3 = lshr i32 %Y, 22<br><span class="Apple-tab-span" style="white-space: pre;"> </span>%tmp57 = or i32 %tmp3, %tmp1<br><span class="Apple-tab-span" style="white-space: pre;"> </span>ret i32 %tmp57<br>}<br>+<br>+; CHECK: test9:<br>+; CHECK: pkhtb r0, r0, r1, asr #16<br>+define i32 @test9(i32 %src1, i32 %src2) {<br>+entry:<br>+ %tmp = and i32 %src1, -65536<br>+ %tmp2 = lshr i32 %src2, 16<br>+ %tmp3 = or i32 %tmp, %tmp2<br>+ ret i32 %tmp3<br>+}<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></div></blockquote></div><br></div></body></html>