[PATCH] D30004: [InstCombin] Continue scanning loaded values through single predecessors

Jun Bum Lim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 15 12:15:00 PST 2017


junbuml created this revision.

This change allow continue scanning to find a loaded value through single predecessors, instead of being limited within the current block, while respecting the backward scan limit.


https://reviews.llvm.org/D30004

Files:
  lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  test/Transforms/InstCombine/2011-06-13-nsw-alloca.ll
  test/Transforms/InstCombine/load.ll


Index: test/Transforms/InstCombine/load.ll
===================================================================
--- test/Transforms/InstCombine/load.ll
+++ test/Transforms/InstCombine/load.ll
@@ -238,3 +238,15 @@
   store %swift.error* %err.res, %swift.error** %err, align 8
   ret void
 }
+
+; Check that %ld is removed as it loads from the same location to which %a is stored in
+; %entry.
+define i32 @test20(i32* %P, i32 %a) {
+entry:
+  store i32 %a, i32 * %P
+  br label %return
+
+return:                                           ; preds = %entry
+  %ld = load i32 , i32* %P
+  ret i32 %ld
+}
Index: test/Transforms/InstCombine/2011-06-13-nsw-alloca.ll
===================================================================
--- test/Transforms/InstCombine/2011-06-13-nsw-alloca.ll
+++ test/Transforms/InstCombine/2011-06-13-nsw-alloca.ll
@@ -1,4 +1,4 @@
-; RUN: opt -S -instcombine < %s | FileCheck %s
+; RUN: opt -S -instcombine -available-load-scan-limit=3 < %s | FileCheck %s
 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
 target triple = "i386-apple-darwin10.0.0"
 
Index: lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -851,8 +851,25 @@
   // separated by a few arithmetic operations.
   BasicBlock::iterator BBI(LI);
   bool IsLoadCSE = false;
-  if (Value *AvailableVal = FindAvailableLoadedValue(
-          &LI, LI.getParent(), BBI, DefMaxInstsToScan, AA, &IsLoadCSE)) {
+  unsigned NumScannedInst = 0;
+  Value *AvailableVal =
+      FindAvailableLoadedValue(&LI, LI.getParent(), BBI, DefMaxInstsToScan, AA,
+                               &IsLoadCSE, &NumScannedInst);
+  // If the current block has a single predecessor, continue scanning through
+  // the single precessor.
+  BasicBlock *SinglePredBB = LI.getParent();
+  while (!AvailableVal && SinglePredBB && BBI == SinglePredBB->begin() &&
+         NumScannedInst < DefMaxInstsToScan) {
+    SinglePredBB = SinglePredBB->getSinglePredecessor();
+    if (SinglePredBB) {
+      BBI = SinglePredBB->end();
+      AvailableVal = FindAvailableLoadedValue(
+            &LI, SinglePredBB, BBI, (DefMaxInstsToScan - NumScannedInst),
+            nullptr, &IsLoadCSE, &NumScannedInst);
+    }
+  }
+
+  if (AvailableVal) {
     if (IsLoadCSE)
       combineMetadataForCSE(cast<LoadInst>(AvailableVal), &LI);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30004.88589.patch
Type: text/x-patch
Size: 2588 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170215/89ab3f8c/attachment.bin>


More information about the llvm-commits mailing list