[llvm] dabb14c - [InstCombine] matchRotate - allow undef in uniform constant rotation amounts (PR46895)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 28 05:45:52 PDT 2020
Author: Simon Pilgrim
Date: 2020-09-28T13:36:13+01:00
New Revision: dabb14cadd356d3628b4f935c735b163a0f68f38
URL: https://github.com/llvm/llvm-project/commit/dabb14cadd356d3628b4f935c735b163a0f68f38
DIFF: https://github.com/llvm/llvm-project/commit/dabb14cadd356d3628b4f935c735b163a0f68f38.diff
LOG: [InstCombine] matchRotate - allow undef in uniform constant rotation amounts (PR46895)
An extension to D87452, we can safely permit undefs in the uniform/splat detection
https://alive2.llvm.org/ce/z/nT-ptN
Differential Revision: https://reviews.llvm.org/D88402
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 5a1216727fbb..085fff16aed3 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2111,7 +2111,7 @@ static Instruction *matchRotate(Instruction &Or) {
// Check for constant shift amounts that sum to the bitwidth.
// TODO: Support non-uniform shift amounts.
const APInt *LC, *RC;
- if (match(L, m_APInt(LC)) && match(R, m_APInt(RC)))
+ if (match(L, m_APIntAllowUndef(LC)) && match(R, m_APIntAllowUndef(RC)))
if (LC->ult(Width) && RC->ult(Width) && (*LC + *RC) == Width)
return L;
diff --git a/llvm/test/Transforms/InstCombine/rotate.ll b/llvm/test/Transforms/InstCombine/rotate.ll
index edd17785b7cd..227e6e2c2cc7 100644
--- a/llvm/test/Transforms/InstCombine/rotate.ll
+++ b/llvm/test/Transforms/InstCombine/rotate.ll
@@ -67,9 +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: [[SHL:%.*]] = shl <2 x i16> [[X:%.*]], <i16 undef, i16 1>
-; CHECK-NEXT: [[SHR:%.*]] = lshr <2 x i16> [[X]], <i16 15, i16 15>
-; CHECK-NEXT: [[R:%.*]] = or <2 x i16> [[SHL]], [[SHR]]
+; 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: ret <2 x i16> [[R]]
;
%shl = shl <2 x i16> %x, <i16 undef, i16 1>
@@ -80,9 +78,7 @@ define <2 x i16> @rotl_v2i16_constant_splat_undef0(<2 x i16> %x) {
define <2 x i16> @rotl_v2i16_constant_splat_undef1(<2 x i16> %x) {
; CHECK-LABEL: @rotl_v2i16_constant_splat_undef1(
-; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i16> [[X:%.*]], <i16 1, i16 1>
-; CHECK-NEXT: [[SHR:%.*]] = lshr <2 x i16> [[X]], <i16 15, i16 undef>
-; CHECK-NEXT: [[R:%.*]] = or <2 x i16> [[SHL]], [[SHR]]
+; 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 1, i16 1>
@@ -106,9 +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: [[SHL:%.*]] = shl <2 x i17> [[X:%.*]], <i17 12, i17 undef>
-; CHECK-NEXT: [[SHR:%.*]] = lshr <2 x i17> [[X]], <i17 undef, i17 5>
-; CHECK-NEXT: [[R:%.*]] = or <2 x i17> [[SHR]], [[SHL]]
+; 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: ret <2 x i17> [[R]]
;
%shl = shl <2 x i17> %x, <i17 12, i17 undef>
@@ -119,9 +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: [[SHL:%.*]] = shl <2 x i17> [[X:%.*]], <i17 12, i17 undef>
-; CHECK-NEXT: [[SHR:%.*]] = lshr <2 x i17> [[X]], <i17 5, i17 undef>
-; CHECK-NEXT: [[R:%.*]] = or <2 x i17> [[SHR]], [[SHL]]
+; 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: ret <2 x i17> [[R]]
;
%shl = shl <2 x i17> %x, <i17 12, i17 undef>
More information about the llvm-commits
mailing list