[llvm] [GISel] Combine shift + trunc + shift pattern (PR #155583)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 9 03:06:07 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h b/llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
index 46e099e09..029375b17 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
@@ -348,9 +348,11 @@ public:
bool matchCommuteShift(MachineInstr &MI, BuildFnTy &MatchInfo) const;
/// Fold (lshr (trunc (lshr x, C1)), C2) -> trunc (shift x, (C1 + C2))
- bool matchLshrOfTruncOfLshr(MachineInstr &MI, LshrOfTruncOfLshr &MatchInfo, MachineInstr &ShiftMI, MachineInstr &TruncMI) const;
+ bool matchLshrOfTruncOfLshr(MachineInstr &MI, LshrOfTruncOfLshr &MatchInfo,
+ MachineInstr &ShiftMI,
+ MachineInstr &TruncMI) const;
void applyLshrOfTruncOfLshr(MachineInstr &MI,
- LshrOfTruncOfLshr &MatchInfo) const;
+ LshrOfTruncOfLshr &MatchInfo) const;
/// Transform a multiply by a power-of-2 value to a left shift.
bool matchCombineMulToShl(MachineInstr &MI, unsigned &ShiftVal) const;
diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index 3527b92bc..6cc0c86bb 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -2094,8 +2094,10 @@ bool CombinerHelper::matchCommuteShift(MachineInstr &MI,
return true;
}
-bool CombinerHelper::matchLshrOfTruncOfLshr(
- MachineInstr &MI, LshrOfTruncOfLshr &MatchInfo, MachineInstr &ShiftMI, MachineInstr &TruncMI) const {
+bool CombinerHelper::matchLshrOfTruncOfLshr(MachineInstr &MI,
+ LshrOfTruncOfLshr &MatchInfo,
+ MachineInstr &ShiftMI,
+ MachineInstr &TruncMI) const {
unsigned ShiftOpcode = MI.getOpcode();
assert(ShiftOpcode == TargetOpcode::G_LSHR);
@@ -2122,7 +2124,7 @@ bool CombinerHelper::matchLshrOfTruncOfLshr(
MatchInfo.Src = ShiftMI.getOperand(1).getReg();
MatchInfo.ShiftAmt = N1C + N001C;
MatchInfo.ShiftAmtTy = MRI.getType(N001);
- MatchInfo.InnerShiftTy = InnerShiftTy;
+ MatchInfo.InnerShiftTy = InnerShiftTy;
if ((N001C + OpSizeInBits) == InnerShiftSize)
return true;
@@ -2143,9 +2145,12 @@ void CombinerHelper::applyLshrOfTruncOfLshr(
Register Dst = MI.getOperand(0).getReg();
auto ShiftAmt =
Builder.buildConstant(MatchInfo.ShiftAmtTy, MatchInfo.ShiftAmt);
- auto Shift = Builder.buildLShr(MatchInfo.InnerShiftTy, MatchInfo.Src, ShiftAmt);
+ auto Shift =
+ Builder.buildLShr(MatchInfo.InnerShiftTy, MatchInfo.Src, ShiftAmt);
if (MatchInfo.Mask == true) {
- APInt MaskVal = APInt::getLowBitsSet(MatchInfo.InnerShiftTy.getScalarSizeInBits(), MatchInfo.MaskVal.getZExtValue());
+ APInt MaskVal =
+ APInt::getLowBitsSet(MatchInfo.InnerShiftTy.getScalarSizeInBits(),
+ MatchInfo.MaskVal.getZExtValue());
auto Mask = Builder.buildConstant(MatchInfo.ShiftAmtTy, MaskVal);
auto And = Builder.buildAnd(MatchInfo.InnerShiftTy, Shift, Mask);
Builder.buildTrunc(Dst, And);
``````````
</details>
https://github.com/llvm/llvm-project/pull/155583
More information about the llvm-commits
mailing list