[llvm] 63ee42a - [InstCombine] matchRotate - force splat of uniform constant rotation amounts (PR46895)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 28 07:14:14 PDT 2020


Author: Simon Pilgrim
Date: 2020-09-28T15:12:41+01:00
New Revision: 63ee42a06bdb716f80ffc96ff8aa4162ed982e33

URL: https://github.com/llvm/llvm-project/commit/63ee42a06bdb716f80ffc96ff8aa4162ed982e33
DIFF: https://github.com/llvm/llvm-project/commit/63ee42a06bdb716f80ffc96ff8aa4162ed982e33.diff

LOG: [InstCombine] matchRotate - force splat of uniform constant rotation amounts (PR46895)

Fixes minor bug in D88402 where we were using the original shift constant (with undefs) instead of one with the splat values (re)splatted to all elements.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
    llvm/test/Transforms/InstCombine/rotate.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 085fff16aed3..cbc3f5a2532f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2113,7 +2113,7 @@ static Instruction *matchRotate(Instruction &Or) {
     const APInt *LC, *RC;
     if (match(L, m_APIntAllowUndef(LC)) && match(R, m_APIntAllowUndef(RC)))
       if (LC->ult(Width) && RC->ult(Width) && (*LC + *RC) == Width)
-        return L;
+        return ConstantInt::get(L->getType(), *LC);
 
     // For non-constant cases we don't support non-pow2 shift masks.
     // TODO: Is it worth matching urem as well?

diff  --git a/llvm/test/Transforms/InstCombine/rotate.ll b/llvm/test/Transforms/InstCombine/rotate.ll
index 227e6e2c2cc7..514c1d6cf7d8 100644
--- a/llvm/test/Transforms/InstCombine/rotate.ll
+++ b/llvm/test/Transforms/InstCombine/rotate.ll
@@ -67,7 +67,7 @@ define <2 x i16> @rotl_v2i16_constant_splat(<2 x i16> %x) {
 
 define <2 x i16> @rotl_v2i16_constant_splat_undef0(<2 x i16> %x) {
 ; CHECK-LABEL: @rotl_v2i16_constant_splat_undef0(
-; CHECK-NEXT:    [[R:%.*]] = call <2 x i16> @llvm.fshl.v2i16(<2 x i16> [[X:%.*]], <2 x i16> [[X]], <2 x i16> <i16 0, i16 1>)
+; CHECK-NEXT:    [[R:%.*]] = call <2 x i16> @llvm.fshl.v2i16(<2 x i16> [[X:%.*]], <2 x i16> [[X]], <2 x i16> <i16 1, i16 1>)
 ; CHECK-NEXT:    ret <2 x i16> [[R]]
 ;
   %shl = shl <2 x i16> %x, <i16 undef, i16 1>
@@ -102,7 +102,7 @@ define <2 x i17> @rotr_v2i17_constant_splat(<2 x i17> %x) {
 
 define <2 x i17> @rotr_v2i17_constant_splat_undef0(<2 x i17> %x) {
 ; CHECK-LABEL: @rotr_v2i17_constant_splat_undef0(
-; CHECK-NEXT:    [[R:%.*]] = call <2 x i17> @llvm.fshl.v2i17(<2 x i17> [[X:%.*]], <2 x i17> [[X]], <2 x i17> <i17 0, i17 12>)
+; CHECK-NEXT:    [[R:%.*]] = call <2 x i17> @llvm.fshl.v2i17(<2 x i17> [[X:%.*]], <2 x i17> [[X]], <2 x i17> <i17 12, i17 12>)
 ; CHECK-NEXT:    ret <2 x i17> [[R]]
 ;
   %shl = shl <2 x i17> %x, <i17 12, i17 undef>
@@ -113,7 +113,7 @@ define <2 x i17> @rotr_v2i17_constant_splat_undef0(<2 x i17> %x) {
 
 define <2 x i17> @rotr_v2i17_constant_splat_undef1(<2 x i17> %x) {
 ; CHECK-LABEL: @rotr_v2i17_constant_splat_undef1(
-; CHECK-NEXT:    [[R:%.*]] = call <2 x i17> @llvm.fshl.v2i17(<2 x i17> [[X:%.*]], <2 x i17> [[X]], <2 x i17> <i17 12, i17 0>)
+; CHECK-NEXT:    [[R:%.*]] = call <2 x i17> @llvm.fshl.v2i17(<2 x i17> [[X:%.*]], <2 x i17> [[X]], <2 x i17> <i17 12, i17 12>)
 ; CHECK-NEXT:    ret <2 x i17> [[R]]
 ;
   %shl = shl <2 x i17> %x, <i17 12, i17 undef>


        


More information about the llvm-commits mailing list