Skip to content

Commit 47f3649

Browse files
committed
[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. llvm-svn: 255786
1 parent b51460c commit 47f3649

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,8 +1603,8 @@ static void adjustSubwordCmp(SelectionDAG &DAG, SDLoc DL, Comparison &C) {
16031603
} else if (Load->getExtensionType() == ISD::ZEXTLOAD) {
16041604
if (Value > Mask)
16051605
return;
1606-
assert(C.ICmpType == SystemZICMP::Any &&
1607-
"Signedness shouldn't matter here.");
1606+
// If the constant is in range, we can use any comparison.
1607+
C.ICmpType = SystemZICMP::Any;
16081608
} else
16091609
return;
16101610

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; This used to crash the backend due to a failed assertion.
2+
; No particular output expected, but must compile.
3+
;
4+
; RUN: llc < %s -mtriple=s390x-linux-gnu
5+
6+
define void @test(i16 *%input, i32 *%result) {
7+
entry:
8+
%0 = load i16, i16* %input, align 2
9+
%1 = zext i16 %0 to i32
10+
%2 = icmp slt i32 %1, 0
11+
br i1 %2, label %if.then, label %if.else
12+
13+
if.then:
14+
store i32 1, i32* %result, align 4
15+
br label %return
16+
17+
if.else:
18+
store i32 0, i32* %result, align 4
19+
br label %return
20+
21+
return:
22+
ret void
23+
}
24+

0 commit comments

Comments
 (0)