[llvm] r255786 - [SystemZ] Fix assertion failure in adjustSubwordCmp

Ulrich Weigand via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 10:04:06 PST 2015


Author: uweigand
Date: Wed Dec 16 12:04:06 2015
New Revision: 255786

URL: http://llvm.org/viewvc/llvm-project?rev=255786&view=rev
Log:
[SystemZ] Fix assertion failure in adjustSubwordCmp

When comparing a zero-extended value against a constant small enough to
be in range of the inner type, it doesn't matter whether a signed or
unsigned compare operation (for the outer type) is being used.  This is
why the code in adjustSubwordCmp had this assertion:

    assert(C.ICmpType == SystemZICMP::Any &&
           "Signedness shouldn't matter here.");

assuming the the caller had already detected that fact.  However, it
turns out that there cases, in particular with always-true or always-
false conditions that have not been eliminated when compiling at -O0,
where this is not true.

Instead of failing an assertion if C.ICmpType is not SystemZICMP::Any
here, we can simply *set* it safely to SystemZICMP::Any, however.


Added:
    llvm/trunk/test/CodeGen/SystemZ/int-cmp-52.ll
Modified:
    llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp

Modified: llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp?rev=255786&r1=255785&r2=255786&view=diff
==============================================================================
--- llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp Wed Dec 16 12:04:06 2015
@@ -1603,8 +1603,8 @@ static void adjustSubwordCmp(SelectionDA
   } else if (Load->getExtensionType() == ISD::ZEXTLOAD) {
     if (Value > Mask)
       return;
-    assert(C.ICmpType == SystemZICMP::Any &&
-           "Signedness shouldn't matter here.");
+    // If the constant is in range, we can use any comparison.
+    C.ICmpType = SystemZICMP::Any;
   } else
     return;
 

Added: llvm/trunk/test/CodeGen/SystemZ/int-cmp-52.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SystemZ/int-cmp-52.ll?rev=255786&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/SystemZ/int-cmp-52.ll (added)
+++ llvm/trunk/test/CodeGen/SystemZ/int-cmp-52.ll Wed Dec 16 12:04:06 2015
@@ -0,0 +1,24 @@
+; This used to crash the backend due to a failed assertion.
+; No particular output expected, but must compile.
+;
+; RUN: llc < %s -mtriple=s390x-linux-gnu
+
+define void @test(i16 *%input, i32 *%result) {
+entry:
+  %0 = load i16, i16* %input, align 2
+  %1 = zext i16 %0 to i32
+  %2 = icmp slt i32 %1, 0
+  br i1 %2, label %if.then, label %if.else
+
+if.then:
+  store i32 1, i32* %result, align 4
+  br label %return
+
+if.else:
+  store i32 0, i32* %result, align 4
+  br label %return
+
+return:
+  ret void
+}
+




More information about the llvm-commits mailing list