fhahn added a comment. In D87163#2274549 <https://reviews.llvm.org/D87163#2274549>, @dmajor wrote:
> Reduced a bit more: https://godbolt.org/z/j59evK (C++) and > https://godbolt.org/z/8xG688 (IR) -- the store at line 43 of `while.end` has > been removed. Thanks! I reverted the change for now in fb109c42d91c <https://reviews.llvm.org/rGfb109c42d91c30c8c7497ef1fd7aff6f2969c6e7>. I think the problem here is that the load in the loop has `liveOnEntry` as defining access (which is outside the loop), so according to MemorySSA, the load does not read the memory written by the store. A slightly further IR example with the MemorySSA printed: https://godbolt.org/z/G34oM4. I think this is similar to the issue https://bugs.llvm.org/show_bug.cgi?id=47498. @asbirlea do you have any thoughts on the issue? Do I understand correctly that in the example, `%use = load i32, i32* %ptr.1, align 4` should have `; 8 = MemoryPhi({entry,1},{loop.latch,7})` as defining access? define i32 @test() { entry: %nodeStack = alloca [12 x i32], align 4 %nodeStack.cast = bitcast [12 x i32]* %nodeStack to i8* ; 1 = MemoryDef(liveOnEntry) %c.1 = call i1 @cond(i32 1) br i1 %c.1, label %cleanup, label %loop.header loop.header: ; preds = %loop.latch, %entry ; 8 = MemoryPhi({entry,1},{loop.latch,7}) %depth.1 = phi i32 [ %depth.1.be, %loop.latch ], [ 0, %entry ] %cmp = icmp sgt i32 %depth.1, 0 br i1 %cmp, label %cond.read, label %cond.store cond.read: ; preds = %loop.header %sub = add nsw i32 %depth.1, -1 %ptr.1 = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i32 %sub ; MemoryUse(liveOnEntry) %use = load i32, i32* %ptr.1, align 4 ; 2 = MemoryDef(8) %c.2 = call i1 @cond(i32 %use) br i1 %c.2, label %loop.latch, label %cond.store cond.store: ; preds = %cond.read, %loop.header ; 9 = MemoryPhi({loop.header,8},{cond.read,2}) %ptr.2 = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i32 %depth.1 ; 3 = MemoryDef(9) store i32 10, i32* %ptr.2, align 4 %inc = add nsw i32 %depth.1, 1 ; 4 = MemoryDef(3) %c.3 = call i1 @cond(i32 20) br i1 %c.3, label %cleanup, label %loop.latch loop.latch: ; preds = %cond.store, %cond.read ; 7 = MemoryPhi({cond.read,2},{cond.store,4}) %depth.1.be = phi i32 [ %sub, %cond.read ], [ %inc, %cond.store ] br label %loop.header cleanup: ; preds = %cond.store, %entry ; 6 = MemoryPhi({entry,1},{cond.store,4}) ; 5 = MemoryDef(6) call void @llvm.lifetime.end.p0i8(i64 48, i8* nonnull %nodeStack.cast) ret i32 20 } Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D87163/new/ https://reviews.llvm.org/D87163 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits