Skip to content

Commit 0154886

Browse files
UmeshKalappatstellar
authored andcommitted
[PowerPC] Change long to int64_t (which is always 64 bit or 8 bytes )
We can't guarantee the long always 64 bits like WINDOWS or LLP64 data model (rare but we should consider). So use int64_t from inttypes.h and safe in this case. Fixes #55911 . (cherry picked from commit f38ea84)
1 parent 786a4f4 commit 0154886

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

llvm/lib/Target/PowerPC/PPCFastISel.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ bool PPCFastISel::PPCEmitCmp(const Value *SrcValue1, const Value *SrcValue2,
831831
// FIXME: Operands are not in canonical order at -O0, so an immediate
832832
// operand in position 1 is a lost opportunity for now. We are
833833
// similar to ARM in this regard.
834-
long Imm = 0;
834+
int64_t Imm = 0;
835835
bool UseImm = false;
836836
const bool HasSPE = Subtarget->hasSPE();
837837

@@ -841,7 +841,8 @@ bool PPCFastISel::PPCEmitCmp(const Value *SrcValue1, const Value *SrcValue2,
841841
if (SrcVT == MVT::i64 || SrcVT == MVT::i32 || SrcVT == MVT::i16 ||
842842
SrcVT == MVT::i8 || SrcVT == MVT::i1) {
843843
const APInt &CIVal = ConstInt->getValue();
844-
Imm = (IsZExt) ? (long)CIVal.getZExtValue() : (long)CIVal.getSExtValue();
844+
Imm = (IsZExt) ? (int64_t)CIVal.getZExtValue() :
845+
(int64_t)CIVal.getSExtValue();
845846
if ((IsZExt && isUInt<16>(Imm)) || (!IsZExt && isInt<16>(Imm)))
846847
UseImm = true;
847848
}

llvm/test/CodeGen/PowerPC/pr55911.ll

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; RUN: llc -fast-isel=1 -mcpu=ppc64 -mtriple=powerpc64 < %s | FileCheck %s
2+
; Check for non immediate compare insn.
3+
4+
; ModuleID = 'test.c'
5+
source_filename = "test.c"
6+
target datalayout = "E-m:e-i64:64-n32:64"
7+
target triple = "ppc64"
8+
9+
@.str = private unnamed_addr constant [9 x i8] c"correct\0A\00", align 1
10+
@.str.1 = private unnamed_addr constant [11 x i8] c"incorrect\0A\00", align 1
11+
12+
; Function Attrs: noinline nounwind optnone uwtable
13+
define dso_local signext i32 @myTest() #0 {
14+
%1 = alloca i64, align 8
15+
%2 = alloca i64, align 8
16+
store i64 4660, ptr %1, align 8
17+
store i64 140737488355328, ptr %2, align 8
18+
%3 = load i64, ptr %1, align 8
19+
%4 = icmp ult i64 %3, 140737488355328
20+
br i1 %4, label %5, label %7
21+
22+
5: ; preds = %0
23+
%6 = call signext i32 (ptr, ...) @printf(ptr noundef @.str)
24+
br label %9
25+
26+
7: ; preds = %0
27+
%8 = call signext i32 (ptr, ...) @printf(ptr noundef @.str.1)
28+
br label %9
29+
30+
9: ; preds = %7, %5
31+
ret i32 0
32+
}
33+
34+
declare signext i32 @printf(ptr noundef, ...) #1
35+
36+
; CHECK-LABEL: myTest:
37+
; CHECK: # %bb.0:
38+
; CHECK: mflr 0
39+
; CHECK: li 3, 1
40+
; CHECK: sldi 3, 3, 47
41+
; CHECK: ld 4, 120(1)
42+
; CHECK: cmpld 4, 3

0 commit comments

Comments
 (0)