[llvm] r323635 - [X86FixupBWInsts] Fix miscompilation if sibling sub-register is live.
Andrei Elovikov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 29 01:26:04 PST 2018
Author: a.elovikov
Date: Mon Jan 29 01:26:04 2018
New Revision: 323635
URL: http://llvm.org/viewvc/llvm-project?rev=323635&view=rev
Log:
[X86FixupBWInsts] Fix miscompilation if sibling sub-register is live.
Summary: The issues was found during D40524.
Reviewers: andrew.w.kaylor, craig.topper, MatzeB
Reviewed By: andrew.w.kaylor
Subscribers: aivchenk, llvm-commits
Differential Revision: https://reviews.llvm.org/D42533
Modified:
llvm/trunk/lib/Target/X86/X86FixupBWInsts.cpp
llvm/trunk/test/CodeGen/X86/fixup-bw-inst.mir
Modified: llvm/trunk/lib/Target/X86/X86FixupBWInsts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FixupBWInsts.cpp?rev=323635&r1=323634&r2=323635&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FixupBWInsts.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FixupBWInsts.cpp Mon Jan 29 01:26:04 2018
@@ -249,15 +249,16 @@ bool FixupBWInstPass::getSuperRegDestIfD
assert((MO.isDef() || MO.isUse()) && "Expected Def or Use only!");
- for (MCSuperRegIterator Supers(OrigDestReg, TRI, true); Supers.isValid();
- ++Supers) {
- if (*Supers == MO.getReg()) {
- if (MO.isDef())
- IsDefined = true;
- else
- return false; // SuperReg Imp-used' -> live before the MI
- }
- }
+ if (MO.isDef() && TRI->isSuperRegisterEq(OrigDestReg, MO.getReg()))
+ IsDefined = true;
+
+ // If MO is a use of any part of the destination register but is not equal
+ // to OrigDestReg or one of its subregisters, we cannot use SuperDestReg.
+ // For example, if OrigDestReg is %al then an implicit use of %ah, %ax,
+ // %eax, or %rax will prevent us from using the %eax register.
+ if (MO.isUse() && !TRI->isSubRegisterEq(OrigDestReg, MO.getReg()) &&
+ TRI->regsOverlap(SuperDestReg, MO.getReg()))
+ return false;
}
// Reg is not Imp-def'ed -> it's live both before/after the instruction.
if (!IsDefined)
Modified: llvm/trunk/test/CodeGen/X86/fixup-bw-inst.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/fixup-bw-inst.mir?rev=323635&r1=323634&r2=323635&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/fixup-bw-inst.mir (original)
+++ llvm/trunk/test/CodeGen/X86/fixup-bw-inst.mir Mon Jan 29 01:26:04 2018
@@ -32,6 +32,8 @@
%t2 = or i16 undef, %t1
ret i16 %t2
}
+
+ define void @test5() {ret void}
...
---
# CHECK-LABEL: name: test1
@@ -199,3 +201,46 @@ body: |
%ax = OR16rr undef %ax, %r9w, implicit-def %eflags
RETQ %ax
...
+
+---
+# CHECK-LABEL: name: test5
+name: test5
+alignment: 4
+exposesReturnsTwice: false
+legalized: false
+regBankSelected: false
+selected: false
+tracksRegLiveness: true
+registers:
+liveins:
+ - { reg: '%ch', reg: '%bl' }
+frameInfo:
+ isFrameAddressTaken: false
+ isReturnAddressTaken: false
+ hasStackMap: false
+ hasPatchPoint: false
+ stackSize: 0
+ offsetAdjustment: 0
+ maxAlignment: 0
+ adjustsStack: false
+ hasCalls: false
+ stackProtector: ''
+ maxCallFrameSize: 0
+ hasOpaqueSPAdjustment: false
+ hasVAStart: false
+ hasMustTailInVarArgFunc: false
+ savePoint: ''
+ restorePoint: ''
+fixedStack:
+stack:
+constants:
+body: |
+ bb.0:
+ successors:
+ liveins: %ch, %bl
+
+ %cl = MOV8rr %bl, implicit-def %cx, implicit killed %ch, implicit-def %eflags
+ ; CHECK: %cl = MOV8rr %bl, implicit-def %cx, implicit killed %ch, implicit-def %eflags
+
+ RETQ %cx
+...
More information about the llvm-commits
mailing list