[llvm] r240526 - Hexagon: Paper over the undefined behaviour introduced by r238692

Justin Bogner mail at justinbogner.com
Wed Jun 24 00:03:07 PDT 2015


Author: bogner
Date: Wed Jun 24 02:03:07 2015
New Revision: 240526

URL: http://llvm.org/viewvc/llvm-project?rev=240526&view=rev
Log:
Hexagon: Paper over the undefined behaviour introduced by r238692

This stops shifting a 32-bit value by such absurd amounts as 96 and
120. We do this by dropping a call to the function that was doing this
entirely, which rather surprisingly doesn't break *any* tests.

I've also added an assert in the misbehaving function to prove that
it's no longer being called with completely invalid arguments.

This change looks pretty bogus and we should probably be reverting
r238692 instead, but this is hard to do with the number of follow ups
that have happened since. It can't be any worse than the undefined
behaviour that was happening before though.

Modified:
    llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp
    llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.h

Modified: llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp?rev=240526&r1=240525&r2=240526&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp Wed Jun 24 02:03:07 2015
@@ -81,6 +81,9 @@ unsigned HexagonResource::setWeight(unsi
   const unsigned MaskWeight = SlotWeight - 1;
   bool Key = (1 << s) & getUnits();
 
+  // TODO: Improve this API so that we can prevent misuse statically.
+  assert(SlotWeight * s < 32 && "Argument to setWeight too large.");
+
   // Calculate relative weight of the insn for the given slot, weighing it the
   // heavier the more restrictive the insn is and the lowest the slots that the
   // insn may be executed in.

Modified: llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.h?rev=240526&r1=240525&r2=240526&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.h (original)
+++ llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.h Wed Jun 24 02:03:07 2015
@@ -35,7 +35,6 @@ public:
 
   void setUnits(unsigned s) {
     Slots = s & ~(~0U << HEXAGON_PACKET_SIZE);
-    setWeight(s);
   };
   unsigned setWeight(unsigned s);
 





More information about the llvm-commits mailing list