[llvm] r285480 - [DAGCombiner] Fix a crash visiting `AND` nodes.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 28 16:55:32 PDT 2016
Author: davide
Date: Fri Oct 28 18:55:32 2016
New Revision: 285480
URL: http://llvm.org/viewvc/llvm-project?rev=285480&view=rev
Log:
[DAGCombiner] Fix a crash visiting `AND` nodes.
Instead of asserting that the shift count is != 0 we just bail out
as it's not profitable trying to optimize a node which will be
removed anyway.
Differential Revision: https://reviews.llvm.org/D26098
Added:
llvm/trunk/test/CodeGen/X86/pr30813.s
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=285480&r1=285479&r2=285480&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Fri Oct 28 18:55:32 2016
@@ -3046,6 +3046,11 @@ SDValue DAGCombiner::visitANDLike(SDValu
unsigned Size = VT.getSizeInBits();
const APInt &AndMask = CAnd->getAPIntValue();
unsigned ShiftBits = CShift->getZExtValue();
+
+ // Bail out, this node will probably disappear anyway.
+ if (ShiftBits == 0)
+ return SDValue();
+
unsigned MaskBits = AndMask.countTrailingOnes();
EVT HalfVT = EVT::getIntegerVT(*DAG.getContext(), Size / 2);
@@ -3064,7 +3069,7 @@ SDValue DAGCombiner::visitANDLike(SDValu
// extended to handle extensions mixed in.
SDValue SL(N0);
- assert(ShiftBits != 0 && MaskBits <= Size);
+ assert(MaskBits <= Size);
// Extracting the highest bit of the low half.
EVT ShiftVT = TLI.getShiftAmountTy(HalfVT, DAG.getDataLayout());
Added: llvm/trunk/test/CodeGen/X86/pr30813.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr30813.s?rev=285480&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/pr30813.s (added)
+++ llvm/trunk/test/CodeGen/X86/pr30813.s Fri Oct 28 18:55:32 2016
@@ -0,0 +1,20 @@
+ .text
+ .file "/home/davide/work/llvm/test/CodeGen/X86/visitand-shift.ll"
+ .globl patatino
+ .p2align 4, 0x90
+ .type patatino, at function
+patatino: # @patatino
+ .cfi_startproc
+# BB#0:
+ # implicit-def: %RAX
+ movzwl (%rax), %ecx
+ movl %ecx, %eax
+ # implicit-def: %RDX
+ movq %rax, (%rdx)
+ retq
+.Lfunc_end0:
+ .size patatino, .Lfunc_end0-patatino
+ .cfi_endproc
+
+
+ .section ".note.GNU-stack","", at progbits
More information about the llvm-commits
mailing list