[PATCH] Improve Cost model for SLPVectorizer when we have a vector division by power of 2

Andrea Di Biagio Andrea_DiBiagio at sn.scee.net
Thu Aug 21 08:21:44 PDT 2014


I have two minor comments, otherwise the patch LGTM!
(see comments below).

Thanks,
Andrea

================
Comment at: lib/Target/X86/X86TargetTransformInfo.cpp:195
@@ +194,3 @@
+      Opd2PropInfo == TargetTransformInfo::OP_PowerOf2)
+    ISD = ISD::SRL;
+
----------------
I think we also have to explicitly set Opd2PropInfo to 'TargetTransformInfo::OP_None.
The shift count of the resulting shift is unlikely to be a power-of-2.

================
Comment at: lib/Target/X86/X86TargetTransformInfo.cpp:203-208
@@ +202,8 @@
+    unsigned Cost =
+        2 * getArithmeticInstrCost(Instruction::AShr, Ty, Op1Info, Op2Info,
+                                   Opd1PropInfo, Opd2PropInfo);
+    Cost += getArithmeticInstrCost(Instruction::LShr, Ty, Op1Info, Op2Info,
+                                   Opd1PropInfo, Opd2PropInfo);
+    Cost += getArithmeticInstrCost(Instruction::Add, Ty, Op1Info, Op2Info,
+                                   Opd1PropInfo, Opd2PropInfo);
+
----------------
Now that I think about it.. it is wrong to pass the old 'Opd1PropInfo' and 'Opd2PropInfo' to those new calls to 'getArithmeticInstrCost' (sorry, that code came from my original suggestion...).

The expanded shifts will have different shift counts which may or may not be powers-of-2. The Add will have different operands, so we cannot reuse the operand properties of the original UDIV/SDIV.

To be conservative here, we have to use the default values for Opd1PropInfo and Opd2PropInfo (OP_None) in each call to 'getArithmeticInstrCost'.

http://reviews.llvm.org/D4971






More information about the llvm-commits mailing list