summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
authorKai Nacke <kai.nacke@redstar.de>2013-09-19 23:00:28 +0000
committerKai Nacke <kai.nacke@redstar.de>2013-09-19 23:00:28 +0000
commitd09bb4614b81cb9969240f7db4b706dbd7f61ec6 (patch)
tree0a14e4de3f792ad7c348aa3cf6ac1aa3d6b30a62 /llvm/test
parent2d967b2751924b7904033b6cfc537fd21b33ccaa (diff)
downloadbcm5719-llvm-d09bb4614b81cb9969240f7db4b706dbd7f61ec6.tar.gz
bcm5719-llvm-d09bb4614b81cb9969240f7db4b706dbd7f61ec6.zip
PR16726: extend rol/ror matching
C-like languages promote types like unsigned short to unsigned int before performing an arithmetic operation. Currently the rotate matcher in the DAGCombiner does not consider this situation. This commit extends the DAGCombiner in the way that the pattern (or (shl ([az]ext x), (*ext y)), (srl ([az]ext x), (*ext (sub 32, y)))) is folded into ([az]ext (rotl x, y)) The matching is restricted to aext and zext because in this cases the upper bits are either undefined or known. Test case is included. This fixes PR16726. llvm-svn: 191049
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/CodeGen/X86/rotate3.ll76
1 files changed, 76 insertions, 0 deletions
diff --git a/llvm/test/CodeGen/X86/rotate3.ll b/llvm/test/CodeGen/X86/rotate3.ll
new file mode 100644
index 00000000000..b92f7c2a60a
--- /dev/null
+++ b/llvm/test/CodeGen/X86/rotate3.ll
@@ -0,0 +1,76 @@
+; Check that (or (shl x, y), (srl x, (sub 32, y))) is folded into (rotl x, y)
+; and (or (shl x, (sub 32, y)), (srl x, r)) into (rotr x, y) even if the
+; argument is zero extended. Fix for PR16726.
+
+; RUN: llc < %s -march=x86-64 -mcpu=corei7 | FileCheck %s
+
+define zeroext i8 @rolbyte(i32 %nBits_arg, i8 %x_arg) nounwind readnone {
+entry:
+ %tmp1 = zext i8 %x_arg to i32
+ %tmp3 = shl i32 %tmp1, %nBits_arg
+ %tmp8 = sub i32 8, %nBits_arg
+ %tmp10 = lshr i32 %tmp1, %tmp8
+ %tmp11 = or i32 %tmp3, %tmp10
+ %tmp12 = trunc i32 %tmp11 to i8
+ ret i8 %tmp12
+}
+; CHECK: rolb %cl, %{{[a-z0-9]+}}
+
+
+define zeroext i8 @rorbyte(i32 %nBits_arg, i8 %x_arg) nounwind readnone {
+entry:
+ %tmp1 = zext i8 %x_arg to i32
+ %tmp3 = lshr i32 %tmp1, %nBits_arg
+ %tmp8 = sub i32 8, %nBits_arg
+ %tmp10 = shl i32 %tmp1, %tmp8
+ %tmp11 = or i32 %tmp3, %tmp10
+ %tmp12 = trunc i32 %tmp11 to i8
+ ret i8 %tmp12
+}
+; CHECK: rorb %cl, %{{[a-z0-9]+}}
+
+define zeroext i16 @rolword(i32 %nBits_arg, i16 %x_arg) nounwind readnone {
+entry:
+ %tmp1 = zext i16 %x_arg to i32
+ %tmp3 = shl i32 %tmp1, %nBits_arg
+ %tmp8 = sub i32 16, %nBits_arg
+ %tmp10 = lshr i32 %tmp1, %tmp8
+ %tmp11 = or i32 %tmp3, %tmp10
+ %tmp12 = trunc i32 %tmp11 to i16
+ ret i16 %tmp12
+}
+; CHECK: rolw %cl, %{{[a-z0-9]+}}
+
+define zeroext i16 @rorword(i32 %nBits_arg, i16 %x_arg) nounwind readnone {
+entry:
+ %tmp1 = zext i16 %x_arg to i32
+ %tmp3 = lshr i32 %tmp1, %nBits_arg
+ %tmp8 = sub i32 16, %nBits_arg
+ %tmp10 = shl i32 %tmp1, %tmp8
+ %tmp11 = or i32 %tmp3, %tmp10
+ %tmp12 = trunc i32 %tmp11 to i16
+ ret i16 %tmp12
+}
+; CHECK: rorw %cl, %{{[a-z0-9]+}}
+
+define i64 @roldword(i64 %nBits_arg, i32 %x_arg) nounwind readnone {
+entry:
+ %tmp1 = zext i32 %x_arg to i64
+ %tmp3 = shl i64 %tmp1, %nBits_arg
+ %tmp8 = sub i64 32, %nBits_arg
+ %tmp10 = lshr i64 %tmp1, %tmp8
+ %tmp11 = or i64 %tmp3, %tmp10
+ ret i64 %tmp11
+}
+; CHECK: roll %cl, %{{[a-z0-9]+}}
+
+define zeroext i64 @rordword(i64 %nBits_arg, i32 %x_arg) nounwind readnone {
+entry:
+ %tmp1 = zext i32 %x_arg to i64
+ %tmp3 = lshr i64 %tmp1, %nBits_arg
+ %tmp8 = sub i64 32, %nBits_arg
+ %tmp10 = shl i64 %tmp1, %tmp8
+ %tmp11 = or i64 %tmp3, %tmp10
+ ret i64 %tmp11
+}
+; CHECK: rorl %cl, %{{[a-z0-9]+}}
OpenPOWER on IntegriCloud