Fix ubsan failures in lane mask shifts
authorKrzysztof Parzyszek <kparzysz@codeaurora.org>
Thu, 15 Dec 2016 16:08:49 +0000 (16:08 +0000)
committerKrzysztof Parzyszek <kparzysz@codeaurora.org>
Thu, 15 Dec 2016 16:08:49 +0000 (16:08 +0000)
llvm-svn: 289826

llvm/utils/TableGen/RegisterInfoEmitter.cpp

index 73ac332..c82eddc 100644 (file)
@@ -778,8 +778,10 @@ RegisterInfoEmitter::emitComposeSubRegIndexLaneMask(raw_ostream &OS,
         "  LaneBitmask Result;\n"
         "  for (const MaskRolOp *Ops = CompositeSequences[IdxA]; !Ops->Mask.none(); ++Ops) {\n"
         "    LaneBitmask::Type M = LaneMask.getAsInteger() & Ops->Mask.getAsInteger();\n"
-        "    unsigned S = Ops->RotateLeft;\n"
-        "    Result |= LaneBitmask((M << S) | (M >> (LaneBitmask::BitWidth - S)));\n"
+        "    if (unsigned S = Ops->RotateLeft)\n"
+        "      Result |= LaneBitmask((M << S) | (M >> (LaneBitmask::BitWidth - S)));\n"
+        "    else\n"
+        "      Result |= LaneBitmask(M);\n"
         "  }\n"
         "  return Result;\n"
         "}\n\n";
@@ -793,8 +795,10 @@ RegisterInfoEmitter::emitComposeSubRegIndexLaneMask(raw_ostream &OS,
         "  LaneBitmask Result;\n"
         "  for (const MaskRolOp *Ops = CompositeSequences[IdxA]; !Ops->Mask.none(); ++Ops) {\n"
         "    LaneBitmask::Type M = LaneMask.getAsInteger();\n"
-        "    unsigned S = Ops->RotateLeft;\n"
-        "    Result |= LaneBitmask((M >> S) | (M << (LaneBitmask::BitWidth - S)));\n"
+        "    if (unsigned S = Ops->RotateLeft)\n"
+        "      Result |= LaneBitmask((M >> S) | (M << (LaneBitmask::BitWidth - S)));\n"
+        "    else\n"
+        "      Result |= LaneBitmask(M);\n"
         "  }\n"
         "  return Result;\n"
         "}\n\n";