[llvm] r321455 - [DAGCombine] Don't combine (and (setne X, 0), (setne X, -1)) --> (setuge (add X, 1), 2) for i1
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 26 06:48:28 PST 2017
Author: rksimon
Date: Tue Dec 26 06:48:28 2017
New Revision: 321455
URL: http://llvm.org/viewvc/llvm-project?rev=321455&view=rev
Log:
[DAGCombine] Don't combine (and (setne X, 0), (setne X, -1)) --> (setuge (add X, 1), 2) for i1
Reduced from oss-fuzz #4773 test case
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/trunk/test/CodeGen/X86/setcc-combine.ll
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=321455&r1=321454&r2=321455&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Tue Dec 26 06:48:28 2017
@@ -3577,7 +3577,8 @@ SDValue DAGCombiner::foldLogicOfSetCCs(b
// TODO: What is the 'or' equivalent of this fold?
// (and (setne X, 0), (setne X, -1)) --> (setuge (add X, 1), 2)
- if (IsAnd && LL == RL && CC0 == CC1 && IsInteger && CC0 == ISD::SETNE &&
+ if (IsAnd && LL == RL && CC0 == CC1 && OpVT.getScalarSizeInBits() > 1 &&
+ IsInteger && CC0 == ISD::SETNE &&
((isNullConstant(LR) && isAllOnesConstant(RR)) ||
(isAllOnesConstant(LR) && isNullConstant(RR)))) {
SDValue One = DAG.getConstant(1, DL, OpVT);
Modified: llvm/trunk/test/CodeGen/X86/setcc-combine.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/setcc-combine.ll?rev=321455&r1=321454&r2=321455&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/setcc-combine.ll (original)
+++ llvm/trunk/test/CodeGen/X86/setcc-combine.ll Tue Dec 26 06:48:28 2017
@@ -183,3 +183,27 @@ define i32 @test_gt_2(<4 x i32> %A, <4 x
ret i32 %t1
}
+; (and (setne X, 0), (setne X, -1)) --> (setuge (add X, 1), 2)
+; Don't combine with i1 - out of range constant
+define void @test_i1_uge(i1 *%A2) {
+; CHECK-LABEL: test_i1_uge:
+; CHECK: # %bb.0:
+; CHECK-NEXT: movb (%rdi), %al
+; CHECK-NEXT: movl %eax, %ecx
+; CHECK-NEXT: xorb $1, %cl
+; CHECK-NEXT: andb %cl, %al
+; CHECK-NEXT: movzbl %al, %eax
+; CHECK-NEXT: andl $1, %eax
+; CHECK-NEXT: negq %rax
+; CHECK-NEXT: andb $1, %cl
+; CHECK-NEXT: movb %cl, (%rdi,%rax)
+; CHECK-NEXT: retq
+ %L5 = load i1, i1* %A2
+ %C3 = icmp ne i1 %L5, true
+ %C8 = icmp eq i1 %L5, false
+ %C9 = icmp ugt i1 %C3, %C8
+ %G3 = getelementptr i1, i1* %A2, i1 %C9
+ store i1 %C3, i1* %G3
+ ret void
+}
+
More information about the llvm-commits
mailing list