[llvm] r353615 - [TargetLowering] avoid miscompile in setcc transform (PR40657)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 9 07:59:02 PST 2019
Author: spatel
Date: Sat Feb 9 07:59:02 2019
New Revision: 353615
URL: http://llvm.org/viewvc/llvm-project?rev=353615&view=rev
Log:
[TargetLowering] avoid miscompile in setcc transform (PR40657)
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/trunk/test/CodeGen/X86/setcc-combine.ll
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp?rev=353615&r1=353614&r2=353615&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp Sat Feb 9 07:59:02 2019
@@ -3074,7 +3074,9 @@ SDValue TargetLowering::SimplifySetCC(EV
return DAG.getSetCC(dl, VT, N0.getOperand(0),
DAG.getConstant(0, dl, N0.getValueType()),
Cond);
- if (N0.getNode()->hasOneUse()) {
+ // The shift is not valid if this is a bool (i1).
+ // TODO: This transform needs evidence to justify its existence.
+ if (N0.getNode()->hasOneUse() && OpVT.getScalarSizeInBits() != 1) {
assert(N0.getOpcode() == ISD::SUB && "Unexpected operation!");
auto &DL = DAG.getDataLayout();
// (Z-X) == X --> Z == X<<1
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=353615&r1=353614&r2=353615&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/setcc-combine.ll (original)
+++ llvm/trunk/test/CodeGen/X86/setcc-combine.ll Sat Feb 9 07:59:02 2019
@@ -262,12 +262,15 @@ define void @test_i1_uge(i1 *%A2) {
ret void
}
-; FIXME: This should not get folded to 0.
+; This should not get folded to 0.
define i64 @PR40657(i8 %var2, i8 %var9) {
; CHECK-LABEL: PR40657:
; CHECK: # %bb.0:
-; CHECK-NEXT: xorl %eax, %eax
+; CHECK-NEXT: notb %sil
+; CHECK-NEXT: addb %dil, %sil
+; CHECK-NEXT: movzbl %sil, %eax
+; CHECK-NEXT: andl $1, %eax
; CHECK-NEXT: retq
%var6 = trunc i8 %var9 to i1
%var7 = trunc i8 175 to i1
More information about the llvm-commits
mailing list