Skip to content

Commit 25bd713

Browse files
committedMar 17, 2017
[x86] avoid adc/sbb assert when both sides of add are zexted (PR32316)
As noted in the comment, we might want to account for this case, but I didn't look at what that would mean for the asm. I'm also not sure why this only reproduces with avx512, but I'm putting a conservative fix in for now to avoid the crash. Also, if both sides of an add are zexted, shouldn't we shrink that add? https://bugs.llvm.org/show_bug.cgi?id=32316 llvm-svn: 298107
1 parent 98e5643 commit 25bd713

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
 

‎llvm/lib/Target/X86/X86ISelLowering.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -34266,12 +34266,16 @@ static SDValue combineAddOrSubToADCOrSBB(SDNode *N, SelectionDAG &DAG) {
3426634266
std::swap(X, Y);
3426734267

3426834268
// Look through a one-use zext.
34269-
if (Y.getOpcode() == ISD::ZERO_EXTEND && Y.hasOneUse())
34269+
bool PeekedThroughZext = false;
34270+
if (Y.getOpcode() == ISD::ZERO_EXTEND && Y.hasOneUse()) {
3427034271
Y = Y.getOperand(0);
34272+
PeekedThroughZext = true;
34273+
}
3427134274

3427234275
// If this is an add, canonicalize a setcc operand to the RHS.
3427334276
// TODO: Incomplete? What if both sides are setcc?
34274-
if (!IsSub && X.getOpcode() == X86ISD::SETCC &&
34277+
// TODO: Should we allow peeking through a zext of the other operand?
34278+
if (!IsSub && !PeekedThroughZext && X.getOpcode() == X86ISD::SETCC &&
3427534279
Y.getOpcode() != X86ISD::SETCC)
3427634280
std::swap(X, Y);
3427734281

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=avx512f %s -o - | FileCheck %s
3+
4+
; This asserted because we didn't account for a zext of a non-SETCC node:
5+
; https://bugs.llvm.org/show_bug.cgi?id=32316
6+
7+
define i8 @PR32316(i8 %t1, i32 %t5, i8 %t8) {
8+
; CHECK-LABEL: PR32316:
9+
; CHECK: # BB#0:
10+
; CHECK-NEXT: xorl %eax, %eax
11+
; CHECK-NEXT: testb %dil, %dil
12+
; CHECK-NEXT: sete %al
13+
; CHECK-NEXT: cmpl %esi, %eax
14+
; CHECK-NEXT: seta %al
15+
; CHECK-NEXT: cmpb $1, %dl
16+
; CHECK-NEXT: sbbb $-1, %al
17+
; CHECK-NEXT: retq
18+
%t2 = icmp eq i8 %t1, 0
19+
%t3 = zext i1 %t2 to i32
20+
%t6 = icmp ugt i32 %t3, %t5
21+
%t7 = zext i1 %t6 to i8
22+
%t9 = icmp ne i8 %t8, 0
23+
%t10 = zext i1 %t9 to i8
24+
%t11 = add i8 %t7, %t10
25+
ret i8 %t11
26+
}
27+

0 commit comments

Comments
 (0)