[llvm-branch-commits] [llvm] c8b4337 - [LoopUnswitch] Add test cases with atomic loads & call

Florian Hahn via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jan 22 07:16:17 PST 2021


Author: Florian Hahn
Date: 2021-01-22T15:10:12Z
New Revision: c8b4337911f4b61724fe62518c83cd6919d56b29

URL: https://github.com/llvm/llvm-project/commit/c8b4337911f4b61724fe62518c83cd6919d56b29
DIFF: https://github.com/llvm/llvm-project/commit/c8b4337911f4b61724fe62518c83cd6919d56b29.diff

LOG: [LoopUnswitch] Add test cases with atomic loads & call

Added: 
    

Modified: 
    llvm/test/Transforms/LoopUnswitch/partial-unswitch.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/LoopUnswitch/partial-unswitch.ll b/llvm/test/Transforms/LoopUnswitch/partial-unswitch.ll
index 63ce82230322..3e4c9369997e 100644
--- a/llvm/test/Transforms/LoopUnswitch/partial-unswitch.ll
+++ b/llvm/test/Transforms/LoopUnswitch/partial-unswitch.ll
@@ -728,3 +728,104 @@ loop.latch:
 exit:
   ret i32 10
 }
+
+; Do not unswitch if the condition depends on an atomic load. Duplicating such
+; loads is not safe.
+; TODO
+define i32 @no_partial_unswitch_atomic_load_unordered(i32* %ptr, i32 %N) {
+; CHECK-LABEL: @no_partial_unswitch_atomic_load_unordered
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    load
+;
+entry:
+  br label %loop.header
+
+loop.header:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
+  %lv = load atomic i32, i32* %ptr unordered, align 4
+  %sc = icmp eq i32 %lv, 100
+  br i1 %sc, label %noclobber, label %clobber
+
+noclobber:
+  br label %loop.latch
+
+clobber:
+  call void @clobber()
+  br label %loop.latch
+
+loop.latch:
+  %c = icmp ult i32 %iv, %N
+  %iv.next = add i32 %iv, 1
+  br i1 %c, label %loop.header, label %exit
+
+exit:
+  ret i32 10
+}
+
+; Do not unswitch if the condition depends on an atomic load. Duplicating such
+; loads is not safe.
+; TODO
+define i32 @no_partial_unswitch_atomic_load_monotonic(i32* %ptr, i32 %N) {
+; CHECK-LABEL: @no_partial_unswitch_atomic_load_monotonic
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    load
+;
+entry:
+  br label %loop.header
+
+loop.header:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
+  %lv = load atomic i32, i32* %ptr monotonic, align 4
+  %sc = icmp eq i32 %lv, 100
+  br i1 %sc, label %noclobber, label %clobber
+
+noclobber:
+  br label %loop.latch
+
+clobber:
+  call void @clobber()
+  br label %loop.latch
+
+loop.latch:
+  %c = icmp ult i32 %iv, %N
+  %iv.next = add i32 %iv, 1
+  br i1 %c, label %loop.header, label %exit
+
+exit:
+  ret i32 10
+}
+
+
+declare i32 @get_value()
+
+; Do not unswitch if the condition depends on a call, that may clobber memory.
+; Duplicating such a call is not safe.
+define i32 @no_partial_unswitch_cond_call(i32* %ptr, i32 %N) {
+; CHECK-LABEL: @no_partial_unswitch_cond_call
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br label %loop.header
+;
+entry:
+  br label %loop.header
+
+loop.header:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
+  %lv = call i32 @get_value()
+  %sc = icmp eq i32 %lv, 100
+  br i1 %sc, label %noclobber, label %clobber
+
+noclobber:
+  br label %loop.latch
+
+clobber:
+  call void @clobber()
+  br label %loop.latch
+
+loop.latch:
+  %c = icmp ult i32 %iv, %N
+  %iv.next = add i32 %iv, 1
+  br i1 %c, label %loop.header, label %exit
+
+exit:
+  ret i32 10
+}


        


More information about the llvm-branch-commits mailing list