llvm.org GIT mirror llvm / 5fc0cc8
[EarlyCSE] Allow forwarding a non-invariant load into an invariant load. Reviewers: sanjoy Subscribers: mcrosier, llvm-commits Differential Revision: https://reviews.llvm.org/D23935 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280265 91177308-0d34-0410-b5e6-96231b3b80d8 Geoff Berry 3 years ago
2 changed file(s) with 8 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
643643 // generation or the load is known to be from an invariant location,
644644 // replace this instruction.
645645 //
646 // A dominating invariant load implies that the location loaded from is
647 // unchanging beginning at the point of the invariant load, so the load
648 // we're CSE'ing _away_ does not need to be invariant, only the available
649 // load we're CSE'ing _to_ does.
646 // If either the dominating load or the current load are invariant, then
647 // we can assume the current load loads the same value as the dominating
648 // load.
650649 LoadValue InVal = AvailableLoads.lookup(MemInst.getPointerOperand());
651650 if (InVal.DefInst != nullptr &&
652 (InVal.Generation == CurrentGeneration || InVal.IsInvariant) &&
651 (InVal.Generation == CurrentGeneration ||
652 InVal.IsInvariant || MemInst.isInvariantLoad()) &&
653653 InVal.MatchingId == MemInst.getMatchingId() &&
654654 // We don't yet handle removing loads with ordering of any kind.
655655 !MemInst.isVolatile() && MemInst.isUnordered() &&
1919 }
2020
2121 define void @f_1(i32* %ptr) {
22 ; We can forward invariant loads to non-invariant loads, since once an
23 ; invariant load has executed, the location loaded from is known to be
24 ; unchanging.
22 ; We can forward invariant loads to non-invariant loads.
2523
2624 ; CHECK-LABEL: @f_1(
2725 ; CHECK: %val0 = load i32, i32* %ptr, !invariant.load !0
3634 }
3735
3836 define void @f_2(i32* %ptr) {
39 ; Negative test -- we can't forward a non-invariant load into an
40 ; invariant load.
37 ; We can forward a non-invariant load into an invariant load.
4138
4239 ; CHECK-LABEL: @f_2(
4340 ; CHECK: %val0 = load i32, i32* %ptr
4441 ; CHECK: call void @clobber_and_use(i32 %val0)
45 ; CHECK: %val1 = load i32, i32* %ptr, !invariant.load !0
46 ; CHECK: call void @clobber_and_use(i32 %val1)
42 ; CHECK: call void @clobber_and_use(i32 %val0)
4743
4844 %val0 = load i32, i32* %ptr
4945 call void @clobber_and_use(i32 %val0)