[PATCH] D59822: [DAGCombiner] Don't allow addcarry if the type of the carry producer is illegal.
Jonas Paulsson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 26 07:53:15 PDT 2019
jonpa created this revision.
jonpa added reviewers: uweigand, deadalnix, spatel.
Herald added a subscriber: jdoerfert.
getAsCarry() checks that the input argument is a carry-producing node before allowing a transformation to addcarry. This patch adds a check to make sure that the carry-producing node is legal. If it is not, it may not remain in a form that is manageable by the backend. The test case causes a compilation failure during instruction selection for this reason on SystemZ.
DAGCombine.cpp patch Patch by Ulrich Weigand.
https://reviews.llvm.org/D59822
Files:
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
test/CodeGen/SystemZ/dag-combine-05.ll
Index: test/CodeGen/SystemZ/dag-combine-05.ll
===================================================================
--- /dev/null
+++ test/CodeGen/SystemZ/dag-combine-05.ll
@@ -0,0 +1,23 @@
+; Test that DAGCombiner does not produce an addcarry node if the carry
+; producer is not legal. This can happen e.g. with an uaddo with a type
+; that is not legal.
+;
+; RUN: llc -mtriple=s390x-linux-gnu -mcpu=z13 -debug-only=isel < %s 2>&1 \
+; RUN: | FileCheck %s
+; REQUIRES: asserts
+
+; CHECK-NOT: addcarry
+; CHECK-NOT: LLVM ERROR: Cannot select: {{.*}} = SystemZISD::GET_CCMASK
+
+define void @fun(i16 %arg0, i16* %src, i32* %dst) {
+bb:
+ %tmp = icmp ult i16 %arg0, 9616
+ %tmp1 = zext i1 %tmp to i32
+ %tmp2 = load i16, i16* %src
+ %tmp3 = add i16 %tmp2, -1
+ %tmp4 = icmp ne i16 %tmp2, 0
+ %tmp5 = zext i1 %tmp4 to i32
+ %tmp6 = add nuw nsw i32 %tmp5, %tmp1
+ store i32 %tmp6, i32* %dst
+ ret void
+}
Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -2324,6 +2324,10 @@
V.getOpcode() != ISD::UADDO && V.getOpcode() != ISD::USUBO)
return SDValue();
+ EVT VT = V.getNode()->getValueType(0);
+ if (!TLI.isOperationLegalOrCustom(V.getOpcode(), VT))
+ return SDValue();
+
// If the result is masked, then no matter what kind of bool it is we can
// return. If it isn't, then we need to make sure the bool type is either 0 or
// 1 and not other values.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59822.192277.patch
Type: text/x-patch
Size: 1547 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190326/6e143e34/attachment.bin>
More information about the llvm-commits
mailing list