[llvm-branch-commits] [llvm-branch] r231702 - Merging r231563 from adibiagio:
Joerg Sonnenberger
joerg at bec.de
Mon Mar 9 14:12:42 PDT 2015
Author: joerg
Date: Mon Mar 9 16:12:42 2015
New Revision: 231702
URL: http://llvm.org/viewvc/llvm-project?rev=231702&view=rev
Log:
Merging r231563 from adibiagio:
[DAGCombiner] Fix wrong folding of AND dag nodes.
This patch fixes the logic in the DAGCombiner that folds an AND node according
to rule: (and (X (load V)), C) -> (X (load V))
An AND between a vector load 'X' and a constant build_vector 'C' can be folded
into the load itself only if we can prove that the AND operation is redundant.
The algorithm implemented by 'visitAND' firstly computes the splat value 'S'
from C, and then checks if S has the lower 'B' bits set (where B is the size in
bits of the vector element type). The algorithm takes into account also the
'undef' bits in the splat mask.
Unfortunately, the algorithm only worked under the assumption that the size of S
is a multiple of the vector element type. With this patch, we conservatively
avoid folding the AND if the splat bits are not compatible with the vector
element type.
Added X86 test and-load-fold.ll
Differential Revision: http://reviews.llvm.org/D8085
Added:
llvm/branches/release_36/test/CodeGen/X86/and-load-fold.ll
- copied, changed from r231563, llvm/trunk/test/CodeGen/X86/and-load-fold.ll
Modified:
llvm/branches/release_36/ (props changed)
llvm/branches/release_36/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Propchange: llvm/branches/release_36/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Mar 9 16:12:42 2015
@@ -1,3 +1,3 @@
/llvm/branches/Apple/Pertwee:110850,110961
/llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,226023,226029,226044,226046,226048,226058,226075,226170-226171,226182,226473,226588,226616,226664,226708,226711,226755,226791,226808-226809,227005,227085,227250,227260-227261,227290,227294,227299,227319,227339,227491,227584,227603,227628,227670,227809,227815,227903,227934,227972,227983,228049,228129,228168,228331,228411,228444,228490,228500,228507,228518,228525,228565,228656,228760-228761,228793,228842,228899,228957,228969,228979,229029,229343,229351-229352,229421,229495,229529,229731,229911,230058
+/llvm/trunk:155241,226023,226029,226044,226046,226048,226058,226075,226170-226171,226182,226473,226588,226616,226664,226708,226711,226755,226791,226808-226809,227005,227085,227250,227260-227261,227290,227294,227299,227319,227339,227491,227584,227603,227628,227670,227809,227815,227903,227934,227972,227983,228049,228129,228168,228331,228411,228444,228490,228500,228507,228518,228525,228565,228656,228760-228761,228793,228842,228899,228957,228969,228979,229029,229343,229351-229352,229421,229495,229529,229731,229911,230058,231563
Modified: llvm/branches/release_36/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_36/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=231702&r1=231701&r2=231702&view=diff
==============================================================================
--- llvm/branches/release_36/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/branches/release_36/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Mon Mar 9 16:12:42 2015
@@ -2788,9 +2788,13 @@ SDValue DAGCombiner::visitAND(SDNode *N)
SplatBitSize = SplatBitSize * 2)
SplatValue |= SplatValue.shl(SplatBitSize);
- Constant = APInt::getAllOnesValue(BitWidth);
- for (unsigned i = 0, n = SplatBitSize/BitWidth; i < n; ++i)
- Constant &= SplatValue.lshr(i*BitWidth).zextOrTrunc(BitWidth);
+ // Make sure that variable 'Constant' is only set if 'SplatBitSize' is a
+ // multiple of 'BitWidth'. Otherwise, we could propagate a wrong value.
+ if (SplatBitSize % BitWidth == 0) {
+ Constant = APInt::getAllOnesValue(BitWidth);
+ for (unsigned i = 0, n = SplatBitSize/BitWidth; i < n; ++i)
+ Constant &= SplatValue.lshr(i*BitWidth).zextOrTrunc(BitWidth);
+ }
}
}
Copied: llvm/branches/release_36/test/CodeGen/X86/and-load-fold.ll (from r231563, llvm/trunk/test/CodeGen/X86/and-load-fold.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_36/test/CodeGen/X86/and-load-fold.ll?p2=llvm/branches/release_36/test/CodeGen/X86/and-load-fold.ll&p1=llvm/trunk/test/CodeGen/X86/and-load-fold.ll&r1=231563&r2=231702&rev=231702&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/and-load-fold.ll (original)
+++ llvm/branches/release_36/test/CodeGen/X86/and-load-fold.ll Mon Mar 9 16:12:42 2015
@@ -8,7 +8,7 @@ define i8 @foo(<4 x i8>* %V) {
; CHECK: ret
entry:
%Vp = bitcast <4 x i8>* %V to <3 x i8>*
- %V3i8 = load <3 x i8>, <3 x i8>* %Vp, align 4
+ %V3i8 = load <3 x i8>* %Vp, align 4
%0 = and <3 x i8> %V3i8, <i8 undef, i8 undef, i8 95>
%1 = extractelement <3 x i8> %0, i64 2
ret i8 %1
More information about the llvm-branch-commits
mailing list