[PATCH] Add Load Combine Pass

hfinkel at anl.gov hfinkel at anl.gov
Wed May 7 02:50:13 PDT 2014


This pass will create unaligned loads. You'll need to use TTI (enhanced if necessary) to check whether or not the target supports unaligned loads of the required type (by, through TTI, calling TLI->allowsUnalignedMemoryAccesses, and making sure such access is considered "fast"). Otherwise, the code generator will end up breaking the load apart again and will likely generate worse code overall.

================
Comment at: lib/Transforms/IPO/PassManagerBuilder.cpp:223
@@ -222,1 +222,3 @@
+  MPM.add(createLoadCombinePass());
+
   if (BBVectorize) {
----------------
Please move this to after BBVectorize as well.

================
Comment at: lib/Transforms/Scalar/LoadCombine.cpp:138
@@ +137,3 @@
+      PrevOffset = L.POP.Offset;
+      PrevSize = L.Load->getType()->getPrimitiveSizeInBits() / 8;
+      AggregateLoads.push_back(L);
----------------
I suspect that this should really be DL->getTypeStoreSize(L.Load->getType()).

(and the same for all of the places that you call getPrimitiveSizeInBits -- which, for one thing, won't work for pointer types).

================
Comment at: lib/Transforms/Scalar/LoadCombine.cpp:143
@@ +142,3 @@
+    if (L.Load->getAlignment() != BaseLoad->getAlignment())
+      continue;
+    if (L.POP.Offset > PrevOffset + PrevSize) {
----------------
This seems to strict. You actually only care that it is not greater, right?

================
Comment at: lib/Transforms/Scalar/LoadCombine.cpp:165
@@ +164,3 @@
+
+static Value *extractInteger(const DataLayout &DL, LoadCombine::BuilderTy &IRB,
+                             Value *V, IntegerType *Ty, uint64_t Offset,
----------------
If no one else has a better suggestion, I'd move this into IRBuilder.

================
Comment at: test/Transforms/LoadCombine/load-combine.ll:46
@@ +45,3 @@
+  %38 = or i64 %34, %37
+  ret i64 %38
+; CHECK: load i64*
----------------
Please add:
CHECK-LABEL: @LoadU64_x64_0

(and similarly to the other tests)

================
Comment at: test/Transforms/LoadCombine/load-combine.ll:47
@@ +46,3 @@
+  ret i64 %38
+; CHECK: load i64*
+; CHECK-NOT: load
----------------
Please also check the alignment on the load.

http://reviews.llvm.org/D3580






More information about the llvm-commits mailing list