[PATCH] D37821: [SimplifyCfg] Don't sink loads/stores to geps of allocas

Ariel Ben-Yehuda via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 13 12:30:30 PDT 2017


arielb1 created this revision.

This makes to workaround to PR30188 be more robust to code that uses structs.

In practice, this improves an optimization case in rustc and reduces in-the-wild Rust code size by 0.1%.


https://reviews.llvm.org/D37821

Files:
  lib/Transforms/Utils/SimplifyCFG.cpp
  test/Transforms/SimplifyCFG/sink-common-code.ll


Index: test/Transforms/SimplifyCFG/sink-common-code.ll
===================================================================
--- test/Transforms/SimplifyCFG/sink-common-code.ll
+++ test/Transforms/SimplifyCFG/sink-common-code.ll
@@ -657,6 +657,31 @@
 ; CHECK: load
 ; CHECK: store
 
+define i32 @test_pr30188b(i1 zeroext %flag, i32 %x) {
+entry:
+  %yy = alloca {i32}
+  %zz = alloca {i32}
+  %y = getelementptr inbounds {i32}, {i32}* %y, i32 0, i32 ,0
+  %z = getelementptr inbounds {i32}, {i32}* %z, i32 0, i32 ,0
+  br i1 %flag, label %if.then, label %if.else
+
+if.then:
+  store i32 %x, i32* %y
+  br label %if.end
+
+if.else:
+  store i32 %x, i32* %z
+  br label %if.end
+
+if.end:
+  ret i32 1
+}
+
+; CHECK-LABEL: test_pr30188b
+; CHECK-NOT: select
+; CHECK: store
+; CHECK: store
+
 ; The phi is confusing - both add instructions are used by it, but
 ; not on their respective unconditional arcs. It should not be
 ; optimized.
Index: lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- lib/Transforms/Utils/SimplifyCFG.cpp
+++ lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1436,11 +1436,11 @@
   // FIXME: This is a workaround for a deficiency in SROA - see
   // https://llvm.org/bugs/show_bug.cgi?id=30188
   if (isa<StoreInst>(I0) && any_of(Insts, [](const Instruction *I) {
-        return isa<AllocaInst>(I->getOperand(1));
+        return isa<AllocaInst>(I->getOperand(1)->stripInBoundsOffsets());
       }))
     return false;
   if (isa<LoadInst>(I0) && any_of(Insts, [](const Instruction *I) {
-        return isa<AllocaInst>(I->getOperand(0));
+        return isa<AllocaInst>(I->getOperand(0)->stripInBoundsOffsets());
       }))
     return false;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37821.115095.patch
Type: text/x-patch
Size: 1721 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170913/7135c549/attachment.bin>


More information about the llvm-commits mailing list