llvm.org GIT mirror llvm / 0077114
Teach RemoveCopyByCommutingDef to check all aliases, not just subregisters. This caused a miscompilation in WebKit where %RAX had conflicting defs when RemoveCopyByCommutingDef was commuting a %EAX use. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112751 91177308-0d34-0410-b5e6-96231b3b80d8 Jakob Stoklund Olesen 10 years ago
2 changed file(s) with 42 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
388388 if (HasOtherReachingDefs(IntA, IntB, AValNo, BValNo))
389389 return false;
390390
391 bool BHasSubRegs = false;
391 // Abort if the aliases of IntB.reg have values that are not simply the
392 // clobbers from the superreg.
392393 if (TargetRegisterInfo::isPhysicalRegister(IntB.reg))
393 BHasSubRegs = *tri_->getSubRegisters(IntB.reg);
394
395 // Abort if the subregisters of IntB.reg have values that are not simply the
396 // clobbers from the superreg.
397 if (BHasSubRegs)
398 for (const unsigned *SR = tri_->getSubRegisters(IntB.reg); *SR; ++SR)
399 if (li_->hasInterval(*SR) &&
400 HasOtherReachingDefs(IntA, li_->getInterval(*SR), AValNo, 0))
394 for (const unsigned *AS = tri_->getAliasSet(IntB.reg); *AS; ++AS)
395 if (li_->hasInterval(*AS) &&
396 HasOtherReachingDefs(IntA, li_->getInterval(*AS), AValNo, 0))
401397 return false;
402398
403399 // If some of the uses of IntA.reg is already coalesced away, return false.
413409 if (ULR->valno == AValNo && JoinedCopies.count(UseMI))
414410 return false;
415411 }
412
413 DEBUG(dbgs() << "\tRemoveCopyByCommutingDef: " << *DefMI);
416414
417415 // At this point we have decided that it is legal to do this
418416 // transformation. Start by commuting the instruction.
477475 if (UseMI->getOperand(0).getReg() != IntB.reg ||
478476 UseMI->getOperand(0).getSubReg())
479477 continue;
480
478
481479 // This copy will become a noop. If it's defining a new val#,
482480 // remove that val# as well. However this live range is being
483481 // extended to the end of the existing live range defined by the copy.
502500 // Remove val#'s defined by copies that will be coalesced away.
503501 for (unsigned i = 0, e = BDeadValNos.size(); i != e; ++i) {
504502 VNInfo *DeadVNI = BDeadValNos[i];
505 if (BHasSubRegs) {
506 for (const unsigned *SR = tri_->getSubRegisters(IntB.reg); *SR; ++SR) {
507 if (!li_->hasInterval(*SR))
503 if (TargetRegisterInfo::isPhysicalRegister(IntB.reg)) {
504 for (const unsigned *AS = tri_->getAliasSet(IntB.reg); *AS; ++AS) {
505 if (!li_->hasInterval(*AS))
508506 continue;
509 LiveInterval &SRLI = li_->getInterval(*SR);
510 if (const LiveRange *SRLR = SRLI.getLiveRangeContaining(DeadVNI->def))
511 SRLI.removeValNo(SRLR->valno);
507 LiveInterval &ASLI = li_->getInterval(*AS);
508 if (const LiveRange *ASLR = ASLI.getLiveRangeContaining(DeadVNI->def))
509 ASLI.removeValNo(ASLR->valno);
512510 }
513511 }
514512 IntB.removeValNo(BDeadValNos[i]);
0 ; RUN: llc < %s -verify-machineinstrs | FileCheck %s
1 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
2 target triple = "x86_64-apple-darwin10.0.0"
3
4 ; This test exercises the alias checking in SimpleRegisterCoalescing::RemoveCopyByCommutingDef.
5
6 define void @f(i32* %w, i32* %h, i8* %_this, i8* %image) nounwind ssp {
7 %x1 = tail call i64 @g(i8* %_this, i8* %image) nounwind ; [#uses=3]
8 %tmp1 = trunc i64 %x1 to i32 ; [#uses=1]
9 ; CHECK: movl (%r{{.*}}), %
10 %x4 = load i32* %h, align 4 ; [#uses=1]
11
12 ; The imull clobbers a 32-bit register.
13 ; CHECK: imull %{{...}}, %e[[CLOBBER:..]]
14 %x5 = mul nsw i32 %x4, %tmp1 ; [#uses=1]
15
16 ; So we cannot use the corresponding 64-bit register anymore.
17 ; CHECK-NOT: shrq $32, %r[[CLOBBER]]
18 %btmp3 = lshr i64 %x1, 32 ; [#uses=1]
19 %btmp4 = trunc i64 %btmp3 to i32 ; [#uses=1]
20
21 ; CHECK: idiv
22 %x6 = sdiv i32 %x5, %btmp4 ; [#uses=1]
23 store i32 %x6, i32* %w, align 4
24 ret void
25 }
26
27 declare i64 @g(i8*, i8*)