Apply upstream patch for rhbz#1862012

This commit is contained in:
serge-sans-paille 2020-09-04 07:43:57 +00:00
parent dab8ed4a93
commit 96b053653f
3 changed files with 104 additions and 88 deletions

View file

@ -0,0 +1,99 @@
From cbea17568f4301582c1d5d43990f089ca6cff522 Mon Sep 17 00:00:00 2001
From: Kai Luo <lkail@cn.ibm.com>
Date: Fri, 28 Aug 2020 01:56:12 +0000
Subject: [PATCH] [PowerPC] PPCBoolRetToInt: Don't translate Constant's
operands
When collecting `i1` values via `findAllDefs`, ignore Constant's
operands, since Constant's operands might not be `i1`.
Fixes https://bugs.llvm.org/show_bug.cgi?id=46923 which causes ICE
```
llvm-project/llvm/lib/IR/Constants.cpp:1924: static llvm::Constant *llvm::ConstantExpr::getZExt(llvm::Constant *, llvm::Type *, bool): Assertion `C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&& "SrcTy must be smaller than DestTy for ZExt!"' failed.
```
Differential Revision: https://reviews.llvm.org/D85007
---
llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp | 15 ++++++-----
llvm/test/CodeGen/PowerPC/pr46923.ll | 29 +++++++++++++++++++++
2 files changed, 38 insertions(+), 6 deletions(-)
create mode 100644 llvm/test/CodeGen/PowerPC/pr46923.ll
diff --git a/llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp b/llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
index acc8b317a22..172f1346c50 100644
--- a/llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
+++ b/llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
@@ -78,9 +78,9 @@ class PPCBoolRetToInt : public FunctionPass {
Value *Curr = WorkList.back();
WorkList.pop_back();
auto *CurrUser = dyn_cast<User>(Curr);
- // Operands of CallInst are skipped because they may not be Bool type,
- // and their positions are defined by ABI.
- if (CurrUser && !isa<CallInst>(Curr))
+ // Operands of CallInst/Constant are skipped because they may not be Bool
+ // type. For CallInst, their positions are defined by ABI.
+ if (CurrUser && !isa<CallInst>(Curr) && !isa<Constant>(Curr))
for (auto &Op : CurrUser->operands())
if (Defs.insert(Op).second)
WorkList.push_back(Op);
@@ -90,6 +90,9 @@ class PPCBoolRetToInt : public FunctionPass {
// Translate a i1 value to an equivalent i32/i64 value:
Value *translate(Value *V) {
+ assert(V->getType() == Type::getInt1Ty(V->getContext()) &&
+ "Expect an i1 value");
+
Type *IntTy = ST->isPPC64() ? Type::getInt64Ty(V->getContext())
: Type::getInt32Ty(V->getContext());
@@ -252,9 +255,9 @@ class PPCBoolRetToInt : public FunctionPass {
auto *First = dyn_cast<User>(Pair.first);
auto *Second = dyn_cast<User>(Pair.second);
assert((!First || Second) && "translated from user to non-user!?");
- // Operands of CallInst are skipped because they may not be Bool type,
- // and their positions are defined by ABI.
- if (First && !isa<CallInst>(First))
+ // Operands of CallInst/Constant are skipped because they may not be Bool
+ // type. For CallInst, their positions are defined by ABI.
+ if (First && !isa<CallInst>(First) && !isa<Constant>(First))
for (unsigned i = 0; i < First->getNumOperands(); ++i)
Second->setOperand(i, BoolToIntMap[First->getOperand(i)]);
}
diff --git a/llvm/test/CodeGen/PowerPC/pr46923.ll b/llvm/test/CodeGen/PowerPC/pr46923.ll
new file mode 100644
index 00000000000..3e9faa60422
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/pr46923.ll
@@ -0,0 +1,29 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-unknown \
+; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s
+
+@bar = external constant i64, align 8
+
+define i1 @foo() {
+; CHECK-LABEL: foo:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: li r3, 0
+; CHECK-NEXT: isel r3, 0, r3, 4*cr5+lt
+; CHECK-NEXT: blr
+entry:
+ br label %next
+
+next:
+ br i1 undef, label %true, label %false
+
+true:
+ br label %end
+
+false:
+ br label %end
+
+end:
+ %a = phi i1 [ icmp ugt (i64 0, i64 ptrtoint (i64* @bar to i64)), %true ],
+ [ icmp ugt (i64 0, i64 2), %false ]
+ ret i1 %a
+}
--
2.25.2

View file

@ -1,86 +0,0 @@
From cf54ca458afff1f7827bfbbc939429a00496c4f7 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar@redhat.com>
Date: Tue, 18 Aug 2020 10:54:49 -0700
Subject: [PATCH] [PowerPC] PPCBoolRetToInt: Skip translation if there is
ConstantExpr
PPCBoolRetToInt collects PHI, Argument, Call and Constant defs related to an `i1` value which later is translated to an `i32`/`i64` value. The `translate` method expects an `i1` value. However, if the `Constant` is a `ConstantExpr`, the type of the `ConstantExpr` might not be `i1`.
Fixes https://bugs.llvm.org/show_bug.cgi?id=46923 which causes ICE
```
llvm-project/llvm/lib/IR/Constants.cpp:1924: static llvm::Constant *llvm::ConstantExpr::getZExt(llvm::Constant *, llvm::Type *, bool): Assertion `C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&& "SrcTy must be smaller than DestTy for ZExt!"' failed.
```
Differential Revision: https://reviews.llvm.org/D85007
---
llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp | 8 ++++--
llvm/test/CodeGen/PowerPC/pr46923.ll | 31 +++++++++++++++++++++
2 files changed, 37 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/CodeGen/PowerPC/pr46923.ll
diff --git a/llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp b/llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
index 2259a29f838..cfe3b3ce2e9 100644
--- a/llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
+++ b/llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
@@ -90,6 +90,9 @@ class PPCBoolRetToInt : public FunctionPass {
// Translate a i1 value to an equivalent i32/i64 value:
Value *translate(Value *V) {
+ assert(V->getType() == Type::getInt1Ty(V->getContext()) &&
+ "Expect an i1 value");
+
Type *IntTy = ST->isPPC64() ? Type::getInt64Ty(V->getContext())
: Type::getInt32Ty(V->getContext());
@@ -227,8 +230,9 @@ class PPCBoolRetToInt : public FunctionPass {
// CallInst. Potentially, bitwise operations (AND, OR, XOR, NOT) and sign
// extension could also be handled in the future.
for (Value *V : Defs)
- if (!isa<PHINode>(V) && !isa<Constant>(V) &&
- !isa<Argument>(V) && !isa<CallInst>(V))
+ if ((!isa<PHINode>(V) && !isa<Constant>(V) && !isa<Argument>(V) &&
+ !isa<CallInst>(V)) ||
+ isa<ConstantExpr>(V))
return false;
for (Value *V : Defs)
diff --git a/llvm/test/CodeGen/PowerPC/pr46923.ll b/llvm/test/CodeGen/PowerPC/pr46923.ll
new file mode 100644
index 00000000000..d6f65508848
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/pr46923.ll
@@ -0,0 +1,31 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-unknown \
+; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s
+
+@bar = external constant i64, align 8
+
+define i1 @foo() {
+; CHECK-LABEL: foo:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: crxor 4*cr5+lt, 4*cr5+lt, 4*cr5+lt
+; CHECK-NEXT: li r3, 0
+; CHECK-NEXT: li r4, 1
+; CHECK-NEXT: isel r3, r4, r3, 4*cr5+lt
+; CHECK-NEXT: blr
+entry:
+ br label %next
+
+next:
+ br i1 undef, label %true, label %false
+
+true:
+ br label %end
+
+false:
+ br label %end
+
+end:
+ %a = phi i1 [ icmp ugt (i64 0, i64 ptrtoint (i64* @bar to i64)), %true ],
+ [ icmp ugt (i64 0, i64 2), %false ]
+ ret i1 %a
+}
--
2.18.1

View file

@ -11,7 +11,7 @@
%global llvm_libdir %{_libdir}/%{name}
%global build_llvm_libdir %{buildroot}%{llvm_libdir}
#%%global rc_ver 6
%global baserelease 2
%global baserelease 3
%global llvm_srcdir llvm-%{version}%{?rc_ver:rc%{rc_ver}}.src
%global maj_ver 10
%global min_ver 0
@ -63,7 +63,7 @@ Patch1: 0001-CMake-Split-test-binary-exports-into-their-own-expor.patch
# https://reviews.llvm.org/D85007
# https://bugzilla.redhat.com/show_bug.cgi?id=1862012
Patch2: 0001-PowerPC-PPCBoolRetToInt-Skip-translation-if-there-is.patch
Patch2: 0001-PowerPC-PPCBoolRetToInt-Don-t-translate-Constant-s-o.patch
BuildRequires: gcc
BuildRequires: gcc-c++
@ -489,6 +489,9 @@ fi
%endif
%changelog
* Fri Sep 04 2020 sguelton@redhat.com - 10.0.1-3
- Apply upstream patch for rhbz#1862012
* Tue Aug 18 2020 Tom Stellard <tstellar@redhat.com> - 10.0.1-2
- Fix rust crash on ppc64le compiling firefox
- rhbz#1862012