llvm.org GIT mirror llvm / eb0fbb2
Merging r292242: ------------------------------------------------------------------------ r292242 | bwilson | 2017-01-17 11:18:57 -0800 (Tue, 17 Jan 2017) | 5 lines Revert r291640 change to fold X86 comparison with atomic_load_add. Even with the fix from r291630, this still causes problems. I get widespread assertion failures in the Swift runtime's WeakRefCount::increment() function. I sent a reduced testcase in reply to the commit. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_40@292243 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 3 years ago
2 changed file(s) with 10 addition(s) and 86 deletion(s). Raw diff Collapse all Expand all
2945429454 return SDValue();
2945529455 }
2945629456
29457 /// Combine brcond/cmov/setcc/.. based on comparing the result of
29458 /// atomic_load_add to use EFLAGS produced by the addition
29459 /// directly if possible. For example:
29460 ///
29461 /// (setcc (cmp (atomic_load_add x, -C) C), COND_E)
29462 /// becomes:
29463 /// (setcc (LADD x, -C), COND_E)
29464 ///
29465 /// and
29457 /// Combine:
2946629458 /// (brcond/cmov/setcc .., (cmp (atomic_load_add x, 1), 0), COND_S)
29467 /// becomes:
29459 /// to:
2946829460 /// (brcond/cmov/setcc .., (LADD x, 1), COND_LE)
29469 ///
29461 /// i.e., reusing the EFLAGS produced by the LOCKed instruction.
2947029462 /// Note that this is only legal for some op/cc combinations.
2947129463 static SDValue combineSetCCAtomicArith(SDValue Cmp, X86::CondCode &CC,
2947229464 SelectionDAG &DAG) {
2948129473 if (!Cmp.hasOneUse())
2948229474 return SDValue();
2948329475
29484 // This applies to variations of the common case:
29476 // This only applies to variations of the common case:
2948529477 // (icmp slt x, 0) -> (icmp sle (add x, 1), 0)
2948629478 // (icmp sge x, 0) -> (icmp sgt (add x, 1), 0)
2948729479 // (icmp sle x, 0) -> (icmp slt (sub x, 1), 0)
2950029492 return SDValue();
2950129493
2950229494 auto *CmpRHSC = dyn_cast(CmpRHS);
29503 if (!CmpRHSC)
29495 if (!CmpRHSC || CmpRHSC->getZExtValue() != 0)
2950429496 return SDValue();
29505 APInt Comparand = CmpRHSC->getAPIntValue();
2950629497
2950729498 const unsigned Opc = CmpLHS.getOpcode();
2950829499
2951829509 if (Opc == ISD::ATOMIC_LOAD_SUB)
2951929510 Addend = -Addend;
2952029511
29521 if (Comparand == -Addend) {
29522 // No change to CC.
29523 } else if (CC == X86::COND_S && Comparand == 0 && Addend == 1) {
29512 if (CC == X86::COND_S && Addend == 1)
2952429513 CC = X86::COND_LE;
29525 } else if (CC == X86::COND_NS && Comparand == 0 && Addend == 1) {
29514 else if (CC == X86::COND_NS && Addend == 1)
2952629515 CC = X86::COND_G;
29527 } else if (CC == X86::COND_G && Comparand == 0 && Addend == -1) {
29516 else if (CC == X86::COND_G && Addend == -1)
2952829517 CC = X86::COND_GE;
29529 } else if (CC == X86::COND_LE && Comparand == 0 && Addend == -1) {
29518 else if (CC == X86::COND_LE && Addend == -1)
2953029519 CC = X86::COND_L;
29531 } else {
29520 else
2953229521 return SDValue();
29533 }
2953429522
2953529523 SDValue LockOp = lowerAtomicArithWithLOCK(CmpLHS, DAG);
2953629524 DAG.ReplaceAllUsesOfValueWith(CmpLHS.getValue(0),
191191 ret i8 %s2
192192 }
193193
194 define i8 @test_sub_1_setcc_eq(i64* %p) #0 {
195 ; CHECK-LABEL: test_sub_1_setcc_eq:
196 ; CHECK: # BB#0: # %entry
197 ; CHECK-NEXT: lock decq (%rdi)
198 ; CHECK-NEXT: sete %al
199 ; CHECK-NEXT: retq
200 entry:
201 %tmp0 = atomicrmw sub i64* %p, i64 1 seq_cst
202 %tmp1 = icmp eq i64 %tmp0, 1
203 %tmp2 = zext i1 %tmp1 to i8
204 ret i8 %tmp2
205 }
206
207 define i8 @test_add_5_setcc_ne(i64* %p) #0 {
208 ; CHECK-LABEL: test_add_5_setcc_ne:
209 ; CHECK: # BB#0: # %entry
210 ; CHECK-NEXT: lock addq $5, (%rdi)
211 ; CHECK-NEXT: setne %al
212 ; CHECK-NEXT: retq
213 entry:
214 %tmp0 = atomicrmw add i64* %p, i64 5 seq_cst
215 %tmp1 = icmp ne i64 %tmp0, -5
216 %tmp2 = zext i1 %tmp1 to i8
217 ret i8 %tmp2
218 }
219
220 define i8 @test_add_5_setcc_ne_comparand_mismatch(i64* %p) #0 {
221 ; CHECK-LABEL: test_add_5_setcc_ne_comparand_mismatch:
222 ; CHECK: # BB#0: # %entry
223 ; CHECK-NEXT: movl $5, %eax
224 ; CHECK-NEXT: lock xaddq %rax, (%rdi)
225 ; CHECK-NEXT: testq %rax, %rax
226 ; CHECK-NEXT: setne %al
227 ; CHECK-NEXT: retq
228 entry:
229 %tmp0 = atomicrmw add i64* %p, i64 5 seq_cst
230 %tmp1 = icmp ne i64 %tmp0, 0
231 %tmp2 = zext i1 %tmp1 to i8
232 ret i8 %tmp2
233 }
234
235 declare void @g()
236 define zeroext i1 @test_sub_1_setcc_jcc(i64* %p) local_unnamed_addr #0 {
237 ; TODO: It's possible to use "lock dec" here, but both uses of the cmp need to
238 ; be updated.
239 ; CHECK-LABEL: test_sub_1_setcc_jcc:
240 ; CHECK: # BB#0: # %entry
241 ; CHECK: movq $-1, %rax
242 ; CHECK-NEXT: lock xaddq %rax, (%rdi)
243 ; CHECK-NEXT: cmpq $1, %rax
244 ; CHECK-NEXT: sete %bl
245 ; CHECK-NEXT: jne
246 entry:
247 %add = atomicrmw volatile add i64* %p, i64 -1 seq_cst
248 %cmp = icmp ne i64 %add, 1
249 %not = xor i1 %cmp, true
250 br i1 %cmp, label %else, label %then
251 then:
252 tail call void @g()
253 br label %else
254 else:
255 ret i1 %not
256 }
257
258194 attributes #0 = { nounwind }