[PATCH] D58705: [X86] Don't peek through bitcasts before checking ISD::isBuildVectorOfConstantSDNodes in combineTruncatedArithmetic

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 26 18:07:14 PST 2019


craig.topper created this revision.
craig.topper added reviewers: RKSimon, spatel.

We don't have any combines that can look through a bitcast to truncate a build vector of constants. So the truncate will stick around and give us something like this pattern (binop (trunc X), (trunc (bitcast (build_vector)))) which has two truncates in it. Which will be reversed by hoistLogicOpWithSameOpcodeHands in the generic DAG combiner. Thus causing an infinite loop.

Even if we had a combine for (truncate (bitcast (build_vector))), I think it would need to be implemented in getNode otherwise DAG combiner visit ordering would probably still visit the binop first and reverse it. Or combineTruncatedArithmetic would need to do its own constant folding.

This came to me as infinite loop a colleague found with ISPC. In his case the bitcast got introduced after type legalization do it being a v4i64 build_vector on a 32-bit target. But that also means you need to have delayed combineTruncatedArithmetic seeing the constant until after type legalization. So my early attempts at a simple test case have failed. I'll keep at it.


https://reviews.llvm.org/D58705

Files:
  lib/Target/X86/X86ISelLowering.cpp


Index: lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- lib/Target/X86/X86ISelLowering.cpp
+++ lib/Target/X86/X86ISelLowering.cpp
@@ -38715,8 +38715,7 @@
       return true;
 
     // See if this is a single use constant which can be constant folded.
-    SDValue BC = peekThroughOneUseBitcasts(Op);
-    return ISD::isBuildVectorOfConstantSDNodes(BC.getNode());
+    return ISD::isBuildVectorOfConstantSDNodes(Op.getNode());
   };
 
   auto TruncateArithmetic = [&](SDValue N0, SDValue N1) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58705.188489.patch
Type: text/x-patch
Size: 551 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190227/643edf53/attachment.bin>


More information about the llvm-commits mailing list