[llvm] Allow shifting instead of masks if the types are legal. (PR #162732)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 9 13:39:39 PDT 2025


https://github.com/AZero13 created https://github.com/llvm/llvm-project/pull/162732

None

>From c044f13b81233ae171a4a1f493cb918e8e4d3dd8 Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Wed, 8 Oct 2025 23:34:47 -0400
Subject: [PATCH] Allow shifting instead of masks if the types are legal.

---
 llvm/include/llvm/CodeGen/TargetLowering.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h
index 88691b931a8d8..9865143edbdfb 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -839,8 +839,11 @@ class LLVM_ABI TargetLoweringBase {
   /// Return true if the variant with 2 variable shifts is preferred.
   /// Return false if there is no preference.
   virtual bool shouldFoldMaskToVariableShiftPair(SDValue X) const {
-    // By default, let's assume that no one prefers shifts.
-    return false;
+    // By default, let's assume that no one prefers shifts for vectors
+    EVT VT = X.getValueType();
+
+    // Prefer shifts for legal types
+    return isOperationLegal(ISD::SHL, VT);
   }
 
   /// Return true if it is profitable to fold a pair of shifts into a mask.



More information about the llvm-commits mailing list