summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/InstCombine/select-cmpxchg.ll
diff options
context:
space:
mode:
authorMatthew Simpson <mssimpso@codeaurora.org>2017-10-31 12:34:02 +0000
committerMatthew Simpson <mssimpso@codeaurora.org>2017-10-31 12:34:02 +0000
commitb6915fbfa2d3b3f0324d96cd698fbac13a5cc2f6 (patch)
tree7518919b1a479ef05e5d84d892fca9a4281f2cf6 /llvm/test/Transforms/InstCombine/select-cmpxchg.ll
parentaee3e26c7251a31b65a0e169d06384fe8e708ffe (diff)
downloadbcm5719-llvm-b6915fbfa2d3b3f0324d96cd698fbac13a5cc2f6.tar.gz
bcm5719-llvm-b6915fbfa2d3b3f0324d96cd698fbac13a5cc2f6.zip
[InstCombine] Simplify selects that test cmpxchg instructions
If a select instruction tests the returned flag of a cmpxchg instruction and selects between the returned value of the cmpxchg instruction and its compare operand, the result of the select will always be equal to its false value. Differential Revision: https://reviews.llvm.org/D39383 llvm-svn: 316994
Diffstat (limited to 'llvm/test/Transforms/InstCombine/select-cmpxchg.ll')
-rw-r--r--llvm/test/Transforms/InstCombine/select-cmpxchg.ll39
1 files changed, 39 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/select-cmpxchg.ll b/llvm/test/Transforms/InstCombine/select-cmpxchg.ll
new file mode 100644
index 00000000000..d14fcad861f
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/select-cmpxchg.ll
@@ -0,0 +1,39 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i64 @cmpxchg_0(i64* %ptr, i64 %compare, i64 %new_value) {
+; CHECK-LABEL: @cmpxchg_0(
+; CHECK-NEXT: %tmp0 = cmpxchg i64* %ptr, i64 %compare, i64 %new_value seq_cst seq_cst
+; CHECK-NEXT: %tmp2 = extractvalue { i64, i1 } %tmp0, 0
+; CHECK-NEXT: ret i64 %tmp2
+;
+ %tmp0 = cmpxchg i64* %ptr, i64 %compare, i64 %new_value seq_cst seq_cst
+ %tmp1 = extractvalue { i64, i1 } %tmp0, 1
+ %tmp2 = extractvalue { i64, i1 } %tmp0, 0
+ %tmp3 = select i1 %tmp1, i64 %compare, i64 %tmp2
+ ret i64 %tmp3
+}
+
+define i64 @cmpxchg_1(i64* %ptr, i64 %compare, i64 %new_value) {
+; CHECK-LABEL: @cmpxchg_1(
+; CHECK-NEXT: %tmp0 = cmpxchg i64* %ptr, i64 %compare, i64 %new_value seq_cst seq_cst
+; CHECK-NEXT: ret i64 %compare
+;
+ %tmp0 = cmpxchg i64* %ptr, i64 %compare, i64 %new_value seq_cst seq_cst
+ %tmp1 = extractvalue { i64, i1 } %tmp0, 1
+ %tmp2 = extractvalue { i64, i1 } %tmp0, 0
+ %tmp3 = select i1 %tmp1, i64 %tmp2, i64 %compare
+ ret i64 %tmp3
+}
+
+define i64 @cmpxchg_2(i64* %ptr, i64 %compare, i64 %new_value) {
+; CHECK-LABEL: @cmpxchg_2(
+; CHECK-NEXT: %tmp0 = cmpxchg i64* %ptr, i64 %compare, i64 %new_value acq_rel monotonic
+; CHECK-NEXT: ret i64 %compare
+;
+ %tmp0 = cmpxchg i64* %ptr, i64 %compare, i64 %new_value acq_rel monotonic
+ %tmp1 = extractvalue { i64, i1 } %tmp0, 1
+ %tmp2 = extractvalue { i64, i1 } %tmp0, 0
+ %tmp3 = select i1 %tmp1, i64 %compare, i64 %tmp2
+ %tmp4 = select i1 %tmp1, i64 %tmp3, i64 %compare
+ ret i64 %tmp4
+}
OpenPOWER on IntegriCloud