[llvm] r318187 - [SystemZ] Do not crash when selecting an OR of two constants

Ulrich Weigand via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 12:00:34 PST 2017


Author: uweigand
Date: Tue Nov 14 12:00:34 2017
New Revision: 318187

URL: http://llvm.org/viewvc/llvm-project?rev=318187&view=rev
Log:
[SystemZ] Do not crash when selecting an OR of two constants

In rare cases, common code will attempt to select an OR of two
constants.  This confuses the logic in splitLargeImmediate,
causing an internal error during isel.  Fixed by simply leaving
this case to common code to handle.

This fixes PR34859.


Modified:
    llvm/trunk/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp
    llvm/trunk/test/CodeGen/SystemZ/int-const-02.ll

Modified: llvm/trunk/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp?rev=318187&r1=318186&r2=318187&view=diff
==============================================================================
--- llvm/trunk/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp Tue Nov 14 12:00:34 2017
@@ -1263,8 +1263,10 @@ void SystemZDAGToDAGISel::Select(SDNode
     // Fall through.
   or_xor:
     // If this is a 64-bit operation in which both 32-bit halves are nonzero,
-    // split the operation into two.
-    if (Node->getValueType(0) == MVT::i64)
+    // split the operation into two.  If both operands here happen to be
+    // constant, leave this to common code to optimize.
+    if (Node->getValueType(0) == MVT::i64 &&
+        Node->getOperand(0).getOpcode() != ISD::Constant)
       if (auto *Op1 = dyn_cast<ConstantSDNode>(Node->getOperand(1))) {
         uint64_t Val = Op1->getZExtValue();
         if (!SystemZ::isImmLF(Val) && !SystemZ::isImmHF(Val)) {

Modified: llvm/trunk/test/CodeGen/SystemZ/int-const-02.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SystemZ/int-const-02.ll?rev=318187&r1=318186&r2=318187&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/SystemZ/int-const-02.ll (original)
+++ llvm/trunk/test/CodeGen/SystemZ/int-const-02.ll Tue Nov 14 12:00:34 2017
@@ -283,3 +283,20 @@ define i64 @f31() {
   call void @foo(i64 32768, i64 65536, i64 4294967296, i64 281474976710656)
   ret i64 42
 }
+
+; Verify that we do not crash on OR with two constant inputs
+; (this was PR34859).
+define i64 @f32(i64 *%ptr) {
+; CHECK-LABEL: f32:
+; CHECK: llihf %r1, 918324340
+; CHECK: oilf %r1, 1806197964
+; CHECK: la %r0, 1(%r1)
+  store i64 -1, i64* %ptr, align 8
+  %1 = load i64, i64* %ptr, align 8
+  %2 = icmp ne i64 %1, 0
+  %3 = zext i1 %2 to i64
+  %4 = or i64 %3, 3944173009226982604
+  store i64 %4, i64* %ptr, align 8
+  ret i64 3944173009226982604
+}
+




More information about the llvm-commits mailing list