[llvm] r236890 - [X86] Fast-ISel was incorrectly always killing the source of a truncate.
Pete Cooper
peter_cooper at apple.com
Fri May 8 11:29:42 PDT 2015
Author: pete
Date: Fri May 8 13:29:42 2015
New Revision: 236890
URL: http://llvm.org/viewvc/llvm-project?rev=236890&view=rev
Log:
[X86] Fast-ISel was incorrectly always killing the source of a truncate.
A trunc from i32 to i1 on x86_64 generates an instruction such as
%vreg19<def> = COPY %vreg9:sub_8bit<kill>; GR8:%vreg19 GR32:%vreg9
However, the copy here should only have the kill flag on the 32-bit path, not the 64-bit one.
Otherwise, we are killing the source of the truncate which could be used later in the program.
Added:
llvm/trunk/test/CodeGen/X86/fast-isel-trunc-kill-subreg.ll
Modified:
llvm/trunk/lib/Target/X86/X86FastISel.cpp
Modified: llvm/trunk/lib/Target/X86/X86FastISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FastISel.cpp?rev=236890&r1=236889&r2=236890&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FastISel.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FastISel.cpp Fri May 8 13:29:42 2015
@@ -2185,6 +2185,7 @@ bool X86FastISel::X86SelectTrunc(const I
return true;
}
+ bool KillInputReg = false;
if (!Subtarget->is64Bit()) {
// If we're on x86-32; we can't extract an i8 from a general register.
// First issue a copy to GR16_ABCD or GR32_ABCD.
@@ -2194,11 +2195,12 @@ bool X86FastISel::X86SelectTrunc(const I
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(TargetOpcode::COPY), CopyReg).addReg(InputReg);
InputReg = CopyReg;
+ KillInputReg = true;
}
// Issue an extract_subreg.
unsigned ResultReg = fastEmitInst_extractsubreg(MVT::i8,
- InputReg, /*Kill=*/true,
+ InputReg, KillInputReg,
X86::sub_8bit);
if (!ResultReg)
return false;
Added: llvm/trunk/test/CodeGen/X86/fast-isel-trunc-kill-subreg.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/fast-isel-trunc-kill-subreg.ll?rev=236890&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/fast-isel-trunc-kill-subreg.ll (added)
+++ llvm/trunk/test/CodeGen/X86/fast-isel-trunc-kill-subreg.ll Fri May 8 13:29:42 2015
@@ -0,0 +1,40 @@
+; RUN: llc %s -o - -fast-isel=true -O1 -verify-machineinstrs | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-unknown"
+
+; This test failed the machine verifier because the trunc at the start of the
+; method was extracing a subreg and killing the source register. The kill flag was
+; invalid here as the source of the trunc could still be used elsewhere.
+
+; CHECK-LABEL: @test
+
+define i32 @test(i32 %block8x8) {
+bb:
+ %tmp9 = trunc i32 %block8x8 to i1
+ %tmp10 = zext i1 %tmp9 to i32
+ %tmp11 = mul i32 %tmp10, 8
+ %tmp12 = zext i32 %tmp11 to i64
+ br label %bb241
+
+bb241: ; preds = %bb241, %bb
+ %lsr.iv3 = phi i64 [ %lsr.iv.next4, %bb241 ], [ %tmp12, %bb ]
+ %lsr.iv1 = phi i32 [ %lsr.iv.next2, %bb241 ], [ 0, %bb ]
+ %lsr.iv.next2 = add nuw nsw i32 %lsr.iv1, 1
+ %lsr.iv.next4 = add i64 %lsr.iv3, 32
+ %exitcond = icmp eq i32 %lsr.iv.next2, 8
+ br i1 %exitcond, label %.preheader.preheader, label %bb241
+
+.preheader.preheader: ; preds = %bb241
+ %tmp18 = lshr i32 %block8x8, 1
+ br label %bb270
+
+bb270: ; preds = %bb270, %.preheader.preheader
+ %lsr.iv = phi i32 [ %lsr.iv.next, %bb270 ], [ %tmp18, %.preheader.preheader ]
+ %lsr.iv.next = add i32 %lsr.iv, 4
+ %tmp272 = icmp slt i32 %lsr.iv.next, 100
+ br i1 %tmp272, label %bb270, label %.loopexit
+
+.loopexit: ; preds = %bb270
+ ret i32 0
+}
More information about the llvm-commits
mailing list