[llvm] InstCombine: sink loads with invariant.load metadata (PR #112692)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 17 05:31:31 PDT 2024


================
@@ -272,3 +272,118 @@ abort:
   call void @abort()
   unreachable
 }
+
+; Loads marked invariant can be sunk across critical edges.
+
+define <4 x float> @invariant_load_metadata(ptr %p, i32 %cond) {
+; CHECK-LABEL: @invariant_load_metadata(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[COND:%.*]], 0
+; CHECK-NEXT:    br i1 [[C]], label [[BLOCK:%.*]], label [[END:%.*]]
+; CHECK:       block:
+; CHECK-NEXT:    call void @fn()
+; CHECK-NEXT:    br label [[END]]
+; CHECK:       end:
+; CHECK-NEXT:    [[V:%.*]] = load <4 x float>, ptr [[P:%.*]], align 16, !invariant.load [[META0:![0-9]+]]
+; CHECK-NEXT:    ret <4 x float> [[V]]
+;
+entry:
+  %v = load <4 x float>, ptr %p, !invariant.load !0
----------------
nikic wrote:

Replace the vector type with a simple `i32` or something please.

https://github.com/llvm/llvm-project/pull/112692


More information about the llvm-commits mailing list