[PowerPC] Guard against illegal selection of add for TargetConstant operands
authorHal Finkel <hfinkel@anl.gov>
Tue, 2 Sep 2014 06:23:54 +0000 (06:23 +0000)
committerHal Finkel <hfinkel@anl.gov>
Tue, 2 Sep 2014 06:23:54 +0000 (06:23 +0000)
r208640 was reverted because it caused a self-hosting failure on ppc64. The
underlying cause was the formation of ISD::ADD nodes with ISD::TargetConstant
operands. Because we have no patterns for 'add' taking 'timm' nodes, these are
selected as r+r add instructions (which is a miscompile). Guard against this
kind of behavior in the future by making the backend crash should this occur
(instead of silently generating invalid output).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216897 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PowerPC/PPCISelDAGToDAG.cpp

index 54ca2469fad9bc50fff643d4a1b51f5ba8f26c98..74f6b18fd03a02f14ce9a52ca4834f086b0dfea1 100644 (file)
@@ -908,6 +908,13 @@ SDNode *PPCDAGToDAGISel::Select(SDNode *N) {
     return nullptr;   // Already selected.
   }
 
+  // In case any misguided DAG-level optimizations form an ADD with a
+  // TargetConstant operand, crash here instead of miscompiling (by selecting
+  // an r+r add instead of some kind of r+i add).
+  if (N->getOpcode() == ISD::ADD &&
+      N->getOperand(1).getOpcode() == ISD::TargetConstant)
+    llvm_unreachable("Invalid ADD with TargetConstant operand");
+
   switch (N->getOpcode()) {
   default: break;