Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIPS] Fix miscompile of 64-bit shift with masked shift amount #71154

Closed
wants to merge 1 commit into from

Conversation

yingopq
Copy link
Contributor

@yingopq yingopq commented Nov 3, 2023

In function lowerShiftRightParts and lowerShiftLeftParts:

  1. xor should use VT.bits-1 not -1;
  2. The comments above the code are incorrect;
  3. ShiftLeftLo and ShiftRightHi are wrong respectively.

Fix #64794

In function lowerShiftRightParts and lowerShiftLeftParts:
1. xor should use VT.bits-1 not -1;
2. The comments above the code are incorrect;
3. ShiftLeftLo and ShiftRightHi are wrong respectively.

Fix llvm#64794
Copy link

github-actions bot commented Nov 3, 2023

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 8e2b3309a975748649a504620a9600da9fe3c837 3d0a76a0fed02d07307c129fd6fbe02d94b74ed9 -- llvm/lib/Target/Mips/MipsISelLowering.cpp
View the diff from clang-format here.
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index 3f6122543c26..269cc397536d 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -2599,7 +2599,7 @@ SDValue MipsTargetLowering::lowerShiftLeftParts(SDValue Op,
   //  hi = (shl lo, shamt[4:0])
   SDValue Not =
       DAG.getNode(ISD::XOR, DL, MVT::i32, Shamt,
-		  DAG.getConstant(VT.getSizeInBits() - 1, DL, MVT::i32));
+                  DAG.getConstant(VT.getSizeInBits() - 1, DL, MVT::i32));
   SDValue ShiftRight1Lo = DAG.getNode(ISD::SRL, DL, VT, Lo,
                                       DAG.getConstant(1, DL, VT));
   SDValue ShiftRightLo = DAG.getNode(ISD::SRL, DL, VT, ShiftRight1Lo, Not);
@@ -2607,7 +2607,7 @@ SDValue MipsTargetLowering::lowerShiftLeftParts(SDValue Op,
   SDValue Or = DAG.getNode(ISD::OR, DL, VT, ShiftLeftHi, ShiftRightLo);
   SDValue ShamtMasked =
       DAG.getNode(ISD::AND, DL, MVT::i32, Shamt,
-		  DAG.getConstant(VT.getSizeInBits() - 1, DL, MVT::i32));
+                  DAG.getConstant(VT.getSizeInBits() - 1, DL, MVT::i32));
   SDValue ShiftLeftLo = DAG.getNode(ISD::SHL, DL, VT, Lo, ShamtMasked);
   SDValue Cond = DAG.getNode(ISD::AND, DL, MVT::i32, Shamt,
                              DAG.getConstant(VT.getSizeInBits(), DL, MVT::i32));
@@ -2641,7 +2641,7 @@ SDValue MipsTargetLowering::lowerShiftRightParts(SDValue Op, SelectionDAG &DAG,
   //   hi = 0
   SDValue Not =
       DAG.getNode(ISD::XOR, DL, MVT::i32, Shamt,
-		  DAG.getConstant(VT.getSizeInBits() - 1, DL, MVT::i32));
+                  DAG.getConstant(VT.getSizeInBits() - 1, DL, MVT::i32));
   SDValue ShiftLeft1Hi = DAG.getNode(ISD::SHL, DL, VT, Hi,
                                      DAG.getConstant(1, DL, VT));
   SDValue ShiftLeftHi = DAG.getNode(ISD::SHL, DL, VT, ShiftLeft1Hi, Not);
@@ -2649,7 +2649,7 @@ SDValue MipsTargetLowering::lowerShiftRightParts(SDValue Op, SelectionDAG &DAG,
   SDValue Or = DAG.getNode(ISD::OR, DL, VT, ShiftLeftHi, ShiftRightLo);
   SDValue ShamtMasked =
       DAG.getNode(ISD::AND, DL, MVT::i32, Shamt,
-		  DAG.getConstant(VT.getSizeInBits() - 1, DL, MVT::i32));
+                  DAG.getConstant(VT.getSizeInBits() - 1, DL, MVT::i32));
   SDValue ShiftRightHi =
       DAG.getNode(IsSRA ? ISD::SRA : ISD::SRL, DL, VT, Hi, ShamtMasked);
   SDValue Cond = DAG.getNode(ISD::AND, DL, MVT::i32, Shamt,

@RKSimon
Copy link
Collaborator

RKSimon commented Nov 3, 2023

Duplicate of #71149 ?

@topperc
Copy link
Collaborator

topperc commented Nov 3, 2023

Missing test updates?

@yingopq
Copy link
Contributor Author

yingopq commented Nov 8, 2023

Duplicate of #71149 ?

Sorry, I would close this pr.

@yingopq yingopq closed this Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MIPS] miscompile of 64-bit shift with masked shift amount
3 participants