]> granicus.if.org Git - llvm/commitdiff
[LoadCombine] Fix combining of loads which span an aliasing store.
authorMichael J. Spencer <bigcheesegs@gmail.com>
Thu, 9 Feb 2017 21:46:49 +0000 (21:46 +0000)
committerMichael J. Spencer <bigcheesegs@gmail.com>
Thu, 9 Feb 2017 21:46:49 +0000 (21:46 +0000)
Fixes PR31517

Differential Revision: https://reviews.llvm.org/D28922

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294632 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoadCombine.cpp
test/Transforms/LoadCombine/load-combine-aa.ll

index 389f1c595aa408b80055884e09c2947e858860f8..61b7804b59b2342c5156c93f00aa3c37b9d8ba45 100644 (file)
@@ -245,13 +245,17 @@ bool LoadCombine::runOnBasicBlock(BasicBlock &BB) {
   bool Combined = false;
   unsigned Index = 0;
   for (auto &I : BB) {
-    if (I.mayThrow() || (I.mayWriteToMemory() && AST.containsUnknown(&I))) {
+    if (I.mayThrow() || AST.containsUnknown(&I)) {
       if (combineLoads(LoadMap))
         Combined = true;
       LoadMap.clear();
       AST.clear();
       continue;
     }
+    if (I.mayWriteToMemory()) {
+      AST.add(&I);
+      continue;
+    }
     LoadInst *LI = dyn_cast<LoadInst>(&I);
     if (!LI)
       continue;
index fc639c0bc05db5b70437d02465d500d763bf89b0..ad66a1a6387c8b48117c902af5ecc3228be095e1 100644 (file)
@@ -37,3 +37,24 @@ define i64 @test2(i32* nocapture readonly %a, i32* nocapture readonly %b) {
   ret i64 %add
 }
 
+%rec11 = type { i16, i16, i16 }
+@str = global %rec11 { i16 1, i16 2, i16 3 }
+
+; PR31517 - Check that loads which span an aliasing store are not combined.
+define i16 @test3() {
+; CHECK-LABEL: @test3
+
+; CHECK: load i16, i16*
+; CHECK: store i16
+; CHECK: ret i16
+
+  %_tmp9 = getelementptr %rec11, %rec11* @str, i16 0, i32 1
+  %_tmp10 = load i16, i16* %_tmp9
+  %_tmp12 = getelementptr %rec11, %rec11* @str, i16 0, i32 0
+  store i16 %_tmp10, i16* %_tmp12
+  %_tmp13 = getelementptr %rec11, %rec11* @str, i16 0, i32 0
+  %_tmp14 = load i16, i16* %_tmp13
+  %_tmp15 = icmp eq i16 %_tmp14, 3
+  %_tmp16 = select i1 %_tmp15, i16 1, i16 0
+  ret i16 %_tmp16
+}