[llvm] 4009529 - [PPC] Fix static analyzer / UBSAN warnings about out of range shifts. NFCI.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 12 02:34:51 PST 2021


Author: Simon Pilgrim
Date: 2021-03-12T10:34:35Z
New Revision: 400952980f4a70f62b75b84b3613cab77bb4fa13

URL: https://github.com/llvm/llvm-project/commit/400952980f4a70f62b75b84b3613cab77bb4fa13
DIFF: https://github.com/llvm/llvm-project/commit/400952980f4a70f62b75b84b3613cab77bb4fa13.diff

LOG: [PPC] Fix static analyzer / UBSAN warnings about out of range shifts. NFCI.

Added: 
    

Modified: 
    llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp b/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
index 3d080d3b9df7..45fab4158939 100644
--- a/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
@@ -941,7 +941,7 @@ static SDNode *selectI64ImmDirect(SelectionDAG *CurDAG, const SDLoc &dl,
   // 63                    0      63                    0
   if ((Shift = findContiguousZerosAtLeast(Imm, 49)) ||
       (Shift = findContiguousZerosAtLeast(~Imm, 49))) {
-    uint64_t RotImm = (Imm >> Shift) | (Imm << (64 - Shift));
+    uint64_t RotImm = APInt(64, Imm).rotr(Shift).getZExtValue();
     Result = CurDAG->getMachineNode(PPC::LI8, dl, MVT::i64,
                                     getI32Imm(RotImm & 0xffff));
     return CurDAG->getMachineNode(PPC::RLDICL, dl, MVT::i64, SDValue(Result, 0),
@@ -1019,7 +1019,7 @@ static SDNode *selectI64ImmDirect(SelectionDAG *CurDAG, const SDLoc &dl,
   // This is similar to Pattern 2-6, please refer to the diagram there.
   if ((Shift = findContiguousZerosAtLeast(Imm, 33)) ||
       (Shift = findContiguousZerosAtLeast(~Imm, 33))) {
-    uint64_t RotImm = (Imm >> Shift) | (Imm << (64 - Shift));
+    uint64_t RotImm = APInt(64, Imm).rotr(Shift).getZExtValue();
     uint64_t ImmHi16 = (RotImm >> 16) & 0xffff;
     unsigned Opcode = ImmHi16 ? PPC::LIS8 : PPC::LI8;
     Result = CurDAG->getMachineNode(Opcode, dl, MVT::i64, getI32Imm(ImmHi16));
@@ -1126,7 +1126,7 @@ static SDNode *selectI64ImmDirectPrefix(SelectionDAG *CurDAG, const SDLoc &dl,
   // +----------------------+     +----------------------+
   // 63                    0      63                    0
   for (unsigned Shift = 0; Shift < 63; ++Shift) {
-    uint64_t RotImm = (Imm >> Shift) | (Imm << (64 - Shift));
+    uint64_t RotImm = APInt(64, Imm).rotr(Shift).getZExtValue();
     if (isInt<34>(RotImm)) {
       Result =
           CurDAG->getMachineNode(PPC::PLI8, dl, MVT::i64, getI64Imm(RotImm));


        


More information about the llvm-commits mailing list