summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2019-08-22 19:56:14 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2019-08-22 19:56:14 +0000
commit2452d7030b84d358165f5f76c9270937b4ea1a91 (patch)
tree86eae755b4033326df037893acdfe1aa3e674f1f /llvm
parent1aeb27af224e670a9ff40da33c3cdb811220d70b (diff)
downloadbcm5719-llvm-2452d7030b84d358165f5f76c9270937b4ea1a91.tar.gz
bcm5719-llvm-2452d7030b84d358165f5f76c9270937b4ea1a91.zip
IR. Change strip* family of functions to not look through aliases.
I noticed another instance of the issue where references to aliases were being replaced with aliasees, this time in InstCombine. In the instance that I saw it turned out to be only a QoI issue (a symbol ended up being missing from the symbol table due to the last reference to the alias being removed, preventing HWASAN from symbolizing a global reference), but it could easily have manifested as incorrect behaviour. Since this is the third such issue encountered (previously: D65118, D65314) it seems to be time to address this common error/QoI issue once and for all and make the strip* family of functions not look through aliases. Includes a test for the specific issue that I saw, but no doubt there are other similar bugs fixed here. As with D65118 this has been tested to make sure that the optimization isn't load bearing. I built Clang, Chromium for Linux, Android and Windows as well as the test-suite and there were no size regressions. Differential Revision: https://reviews.llvm.org/D66606 llvm-svn: 369697
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/IR/Value.h23
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp4
-rw-r--r--llvm/lib/Analysis/ModuleSummaryAnalysis.cpp2
-rw-r--r--llvm/lib/Analysis/StackSafetyAnalysis.cpp4
-rw-r--r--llvm/lib/CodeGen/Analysis.cpp2
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp3
-rw-r--r--llvm/lib/IR/Constants.cpp6
-rw-r--r--llvm/lib/IR/Module.cpp2
-rw-r--r--llvm/lib/IR/Value.cpp30
-rw-r--r--llvm/lib/IR/Verifier.cpp2
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp2
-rw-r--r--llvm/lib/Transforms/IPO/ConstantMerge.cpp2
-rw-r--r--llvm/lib/Transforms/IPO/GlobalOpt.cpp4
-rw-r--r--llvm/test/Transforms/InstCombine/bitcast-alias-function.ll239
-rw-r--r--llvm/test/Transforms/InstCombine/bitcast-function.ll206
-rw-r--r--llvm/test/Transforms/InstCombine/gep-alias.ll15
-rw-r--r--llvm/test/Transforms/InstCombine/pr39177.ll2
17 files changed, 252 insertions, 296 deletions
diff --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h
index 62db353ba53..03d2ce4d7f8 100644
--- a/llvm/include/llvm/IR/Value.h
+++ b/llvm/include/llvm/IR/Value.h
@@ -513,17 +513,17 @@ public:
/// swifterror attribute.
bool isSwiftError() const;
- /// Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
+ /// Strip off pointer casts, all-zero GEPs and address space casts.
///
/// Returns the original uncasted value. If this is called on a non-pointer
/// value, it returns 'this'.
const Value *stripPointerCasts() const;
Value *stripPointerCasts() {
return const_cast<Value *>(
- static_cast<const Value *>(this)->stripPointerCasts());
+ static_cast<const Value *>(this)->stripPointerCasts());
}
- /// Strip off pointer casts, all-zero GEPs, address space casts, and aliases
+ /// Strip off pointer casts, all-zero GEPs and address space casts
/// but ensures the representation of the result stays the same.
///
/// Returns the original uncasted value with the same representation. If this
@@ -534,26 +534,15 @@ public:
->stripPointerCastsSameRepresentation());
}
- /// Strip off pointer casts, all-zero GEPs, aliases and invariant group
- /// info.
+ /// Strip off pointer casts, all-zero GEPs and invariant group info.
///
/// Returns the original uncasted value. If this is called on a non-pointer
/// value, it returns 'this'. This function should be used only in
/// Alias analysis.
const Value *stripPointerCastsAndInvariantGroups() const;
Value *stripPointerCastsAndInvariantGroups() {
- return const_cast<Value *>(
- static_cast<const Value *>(this)->stripPointerCastsAndInvariantGroups());
- }
-
- /// Strip off pointer casts and all-zero GEPs.
- ///
- /// Returns the original uncasted value. If this is called on a non-pointer
- /// value, it returns 'this'.
- const Value *stripPointerCastsNoFollowAliases() const;
- Value *stripPointerCastsNoFollowAliases() {
- return const_cast<Value *>(
- static_cast<const Value *>(this)->stripPointerCastsNoFollowAliases());
+ return const_cast<Value *>(static_cast<const Value *>(this)
+ ->stripPointerCastsAndInvariantGroups());
}
/// Strip off pointer casts and all-constant inbounds GEPs.
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 2d7b4793904..f7cc53b345f 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -781,10 +781,10 @@ Constant *CastGEPIndices(Type *SrcElemTy, ArrayRef<Constant *> Ops,
}
/// Strip the pointer casts, but preserve the address space information.
-Constant* StripPtrCastKeepAS(Constant* Ptr, Type *&ElemTy) {
+Constant *StripPtrCastKeepAS(Constant *Ptr, Type *&ElemTy) {
assert(Ptr->getType()->isPointerTy() && "Not a pointer type");
auto *OldPtrTy = cast<PointerType>(Ptr->getType());
- Ptr = cast<Constant>(Ptr->stripPointerCastsNoFollowAliases());
+ Ptr = cast<Constant>(Ptr->stripPointerCasts());
auto *NewPtrTy = cast<PointerType>(Ptr->getType());
ElemTy = NewPtrTy->getPointerElementType();
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index 29d95d0e989..8232bf07caf 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -319,7 +319,7 @@ static void computeFunctionSummary(ModuleSummaryIndex &Index, const Module &M,
auto *CalledValue = CS.getCalledValue();
auto *CalledFunction = CS.getCalledFunction();
if (CalledValue && !CalledFunction) {
- CalledValue = CalledValue->stripPointerCastsNoFollowAliases();
+ CalledValue = CalledValue->stripPointerCasts();
// Stripping pointer casts can reveal a called function.
CalledFunction = dyn_cast<Function>(CalledValue);
}
diff --git a/llvm/lib/Analysis/StackSafetyAnalysis.cpp b/llvm/lib/Analysis/StackSafetyAnalysis.cpp
index 4cf235db86e..1b363869895 100644
--- a/llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ b/llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -333,8 +333,8 @@ bool StackSafetyLocalAnalysis::analyzeAllUses(const Value *Ptr, UseInfo &US) {
// FIXME: consult devirt?
// Do not follow aliases, otherwise we could inadvertently follow
// dso_preemptable aliases or aliases with interposable linkage.
- const GlobalValue *Callee = dyn_cast<GlobalValue>(
- CS.getCalledValue()->stripPointerCastsNoFollowAliases());
+ const GlobalValue *Callee =
+ dyn_cast<GlobalValue>(CS.getCalledValue()->stripPointerCasts());
if (!Callee) {
US.updateRange(UnknownRange);
return false;
diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp
index f1bbb341df1..3ef90d32daf 100644
--- a/llvm/lib/CodeGen/Analysis.cpp
+++ b/llvm/lib/CodeGen/Analysis.cpp
@@ -156,7 +156,7 @@ void llvm::computeValueLLTs(const DataLayout &DL, Type &Ty,
/// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
GlobalValue *llvm::ExtractTypeInfo(Value *V) {
- V = V->stripPointerCastsNoFollowAliases();
+ V = V->stripPointerCasts();
GlobalValue *GV = dyn_cast<GlobalValue>(V);
GlobalVariable *Var = dyn_cast<GlobalVariable>(V);
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index be2d72a5071..8530174bb6c 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1572,8 +1572,7 @@ bool AsmPrinter::doFinalization(Module &M) {
"expected llvm.used to be an array type");
if (const auto *A = cast<ConstantArray>(LU->getInitializer())) {
for (const Value *Op : A->operands()) {
- const auto *GV =
- cast<GlobalValue>(Op->stripPointerCastsNoFollowAliases());
+ const auto *GV = cast<GlobalValue>(Op->stripPointerCasts());
// Global symbols with internal or private linkage are not visible to
// the linker, and thus would cause an error when the linker tried to
// preserve the symbol due to the `/include:` directive.
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index a78de6a0c84..ee0c1e1f5f6 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -521,10 +521,8 @@ bool Constant::needsRelocation() const {
return false;
// Relative pointers do not need to be dynamically relocated.
- if (auto *LHSGV = dyn_cast<GlobalValue>(
- LHSOp0->stripPointerCastsNoFollowAliases()))
- if (auto *RHSGV = dyn_cast<GlobalValue>(
- RHSOp0->stripPointerCastsNoFollowAliases()))
+ if (auto *LHSGV = dyn_cast<GlobalValue>(LHSOp0->stripPointerCasts()))
+ if (auto *RHSGV = dyn_cast<GlobalValue>(RHSOp0->stripPointerCasts()))
if (LHSGV->isDSOLocal() && RHSGV->isDSOLocal())
return false;
}
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index dbf4035ac7c..25efd009194 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -604,7 +604,7 @@ GlobalVariable *llvm::collectUsedGlobalVariables(
const ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
for (Value *Op : Init->operands()) {
- GlobalValue *G = cast<GlobalValue>(Op->stripPointerCastsNoFollowAliases());
+ GlobalValue *G = cast<GlobalValue>(Op->stripPointerCasts());
Set.insert(G);
}
return GV;
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index b3dcaee766c..c66cbddafd9 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -455,9 +455,8 @@ namespace {
// Various metrics for how much to strip off of pointers.
enum PointerStripKind {
PSK_ZeroIndices,
- PSK_ZeroIndicesAndAliases,
- PSK_ZeroIndicesAndAliasesSameRepresentation,
- PSK_ZeroIndicesAndAliasesAndInvariantGroups,
+ PSK_ZeroIndicesSameRepresentation,
+ PSK_ZeroIndicesAndInvariantGroups,
PSK_InBoundsConstantIndices,
PSK_InBounds
};
@@ -475,10 +474,9 @@ static const Value *stripPointerCastsAndOffsets(const Value *V) {
do {
if (auto *GEP = dyn_cast<GEPOperator>(V)) {
switch (StripKind) {
- case PSK_ZeroIndicesAndAliases:
- case PSK_ZeroIndicesAndAliasesSameRepresentation:
- case PSK_ZeroIndicesAndAliasesAndInvariantGroups:
case PSK_ZeroIndices:
+ case PSK_ZeroIndicesSameRepresentation:
+ case PSK_ZeroIndicesAndInvariantGroups:
if (!GEP->hasAllZeroIndices())
return V;
break;
@@ -494,15 +492,11 @@ static const Value *stripPointerCastsAndOffsets(const Value *V) {
V = GEP->getPointerOperand();
} else if (Operator::getOpcode(V) == Instruction::BitCast) {
V = cast<Operator>(V)->getOperand(0);
- } else if (StripKind != PSK_ZeroIndicesAndAliasesSameRepresentation &&
+ } else if (StripKind != PSK_ZeroIndicesSameRepresentation &&
Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
// TODO: If we know an address space cast will not change the
// representation we could look through it here as well.
V = cast<Operator>(V)->getOperand(0);
- } else if (auto *GA = dyn_cast<GlobalAlias>(V)) {
- if (StripKind == PSK_ZeroIndices || GA->isInterposable())
- return V;
- V = GA->getAliasee();
} else {
if (const auto *Call = dyn_cast<CallBase>(V)) {
if (const Value *RV = Call->getReturnedArgOperand()) {
@@ -512,7 +506,7 @@ static const Value *stripPointerCastsAndOffsets(const Value *V) {
// The result of launder.invariant.group must alias it's argument,
// but it can't be marked with returned attribute, that's why it needs
// special case.
- if (StripKind == PSK_ZeroIndicesAndAliasesAndInvariantGroups &&
+ if (StripKind == PSK_ZeroIndicesAndInvariantGroups &&
(Call->getIntrinsicID() == Intrinsic::launder_invariant_group ||
Call->getIntrinsicID() == Intrinsic::strip_invariant_group)) {
V = Call->getArgOperand(0);
@@ -529,16 +523,11 @@ static const Value *stripPointerCastsAndOffsets(const Value *V) {
} // end anonymous namespace
const Value *Value::stripPointerCasts() const {
- return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliases>(this);
+ return stripPointerCastsAndOffsets<PSK_ZeroIndices>(this);
}
const Value *Value::stripPointerCastsSameRepresentation() const {
- return stripPointerCastsAndOffsets<
- PSK_ZeroIndicesAndAliasesSameRepresentation>(this);
-}
-
-const Value *Value::stripPointerCastsNoFollowAliases() const {
- return stripPointerCastsAndOffsets<PSK_ZeroIndices>(this);
+ return stripPointerCastsAndOffsets<PSK_ZeroIndicesSameRepresentation>(this);
}
const Value *Value::stripInBoundsConstantOffsets() const {
@@ -546,8 +535,7 @@ const Value *Value::stripInBoundsConstantOffsets() const {
}
const Value *Value::stripPointerCastsAndInvariantGroups() const {
- return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliasesAndInvariantGroups>(
- this);
+ return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndInvariantGroups>(this);
}
const Value *
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 6fa58741be1..0350edb2454 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -673,7 +673,7 @@ void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
Assert(InitArray, "wrong initalizer for intrinsic global variable",
Init);
for (Value *Op : InitArray->operands()) {
- Value *V = Op->stripPointerCastsNoFollowAliases();
+ Value *V = Op->stripPointerCasts();
Assert(isa<GlobalVariable>(V) || isa<Function>(V) ||
isa<GlobalAlias>(V),
"invalid llvm.used member", V);
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp
index 494d3fadbc8..750b2233e67 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp
@@ -94,7 +94,7 @@ bool LowerGlobalDtors::runOnModule(Module &M) {
break; // Found a null terminator, skip the rest.
Constant *Associated = CS->getOperand(2);
- Associated = cast<Constant>(Associated->stripPointerCastsNoFollowAliases());
+ Associated = cast<Constant>(Associated->stripPointerCasts());
DtorFuncs[PriorityValue][Associated].push_back(DtorFunc);
}
diff --git a/llvm/lib/Transforms/IPO/ConstantMerge.cpp b/llvm/lib/Transforms/IPO/ConstantMerge.cpp
index ad877ae1786..3fe6f5c8719 100644
--- a/llvm/lib/Transforms/IPO/ConstantMerge.cpp
+++ b/llvm/lib/Transforms/IPO/ConstantMerge.cpp
@@ -48,7 +48,7 @@ static void FindUsedValues(GlobalVariable *LLVMUsed,
ConstantArray *Inits = cast<ConstantArray>(LLVMUsed->getInitializer());
for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i) {
- Value *Operand = Inits->getOperand(i)->stripPointerCastsNoFollowAliases();
+ Value *Operand = Inits->getOperand(i)->stripPointerCasts();
GlobalValue *GV = cast<GlobalValue>(Operand);
UsedValues.insert(GV);
}
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 471cdb66570..7adc9168a0b 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2583,8 +2583,8 @@ static bool EvaluateStaticConstructor(Function *F, const DataLayout &DL,
}
static int compareNames(Constant *const *A, Constant *const *B) {
- Value *AStripped = (*A)->stripPointerCastsNoFollowAliases();
- Value *BStripped = (*B)->stripPointerCastsNoFollowAliases();
+ Value *AStripped = (*A)->stripPointerCasts();
+ Value *BStripped = (*B)->stripPointerCasts();
return AStripped->getName().compare(BStripped->getName());
}
diff --git a/llvm/test/Transforms/InstCombine/bitcast-alias-function.ll b/llvm/test/Transforms/InstCombine/bitcast-alias-function.ll
deleted file mode 100644
index b04308e10e2..00000000000
--- a/llvm/test/Transforms/InstCombine/bitcast-alias-function.ll
+++ /dev/null
@@ -1,239 +0,0 @@
-; RUN: opt -S -instcombine -o - %s | FileCheck %s
-target datalayout = "e-p:32:32:32-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v64:64:64-v128:128:128-a0:0:64"
-
-
-
-; Cases that should be bitcast
-
-; Test cast between scalars with same bit sizes
-@alias_i32_to_f32 = alias float (float), bitcast (i32 (i32)* @func_i32 to float (float)*)
-
-; Test cast between vectors with same number of elements and bit sizes
-@alias_v2i32_to_v2f32 = alias <2 x float> (<2 x float>), bitcast (<2 x i32> (<2 x i32>)* @func_v2i32 to <2 x float> (<2 x float>)*)
-
-; Test cast from vector to scalar with same number of bits
-@alias_v2f32_to_i64 = alias <2 x float> (<2 x float>), bitcast (i64 (i64)* @func_i64 to <2 x float> (<2 x float>)*)
-
-; Test cast from scalar to vector with same number of bits
-@alias_i64_to_v2f32 = alias i64 (i64), bitcast (<2 x float> (<2 x float>)* @func_v2f32 to i64 (i64)*)
-
-; Test cast between vectors of pointers
-@alias_v2i32p_to_v2i64p = alias <2 x i64*> (<2 x i64*>), bitcast (<2 x i32*> (<2 x i32*>)* @func_v2i32p to <2 x i64*> (<2 x i64*>)*)
-
-
-; Cases that should be invalid and unchanged
-
-; Test cast between scalars with different bit sizes
-@alias_i64_to_f32 = alias float (float), bitcast (i64 (i64)* @func_i64 to float (float)*)
-
-; Test cast between vectors with different bit sizes but the
-; same number of elements
-@alias_v2i64_to_v2f32 = alias <2 x float> (<2 x float>), bitcast (<2 x i64> (<2 x i64>)* @func_v2i64 to <2 x float> (<2 x float>)*)
-
-; Test cast between vectors with same number of bits and different
-; numbers of elements
-@alias_v2i32_to_v4f32 = alias <4 x float> (<4 x float>), bitcast (<2 x i32> (<2 x i32>)* @func_v2i32 to <4 x float> (<4 x float>)*)
-
-; Test cast between scalar and vector with different number of bits
-@alias_i64_to_v4f32 = alias i64 (i64), bitcast (<4 x float> (<4 x float>)* @func_v4f32 to i64 (i64)*)
-
-; Test cast between vector and scalar with different number of bits
-@alias_v4f32_to_i64 = alias <4 x float> (<4 x float>), bitcast (i64 (i64)* @func_i64 to <4 x float> (<4 x float>)*)
-
-; Test cast from scalar to vector of pointers with same number of bits
-; We don't know the pointer size at this point, so this can't be done
-@alias_i64_to_v2i32p = alias i64 (i64), bitcast (<2 x i32*> (<2 x i32*>)* @func_v2i32p to i64 (i64)*)
-
-; Test cast between vector of pointers and scalar with different number of bits
-@alias_v4i32p_to_i64 = alias <4 x i32*> (<4 x i32*>), bitcast (i64 (i64)* @func_i64 to <4 x i32*> (<4 x i32*>)*)
-
-
-
-define internal <2 x i32> @func_v2i32(<2 x i32> %v) noinline nounwind {
-entry:
- ret <2 x i32> %v
-}
-
-define internal <2 x float> @func_v2f32(<2 x float> %v) noinline nounwind {
-entry:
- ret <2 x float> %v
-}
-
-define internal <4 x float> @func_v4f32(<4 x float> %v) noinline nounwind {
-entry:
- ret <4 x float> %v
-}
-
-define internal i32 @func_i32(i32 %v) noinline nounwind {
-entry:
- ret i32 %v
-}
-
-define internal i64 @func_i64(i64 %v) noinline nounwind {
-entry:
- ret i64 %v
-}
-
-define internal <2 x i64> @func_v2i64(<2 x i64> %v) noinline nounwind {
-entry:
- ret <2 x i64> %v
-}
-
-define internal <2 x i32*> @func_v2i32p(<2 x i32*> %v) noinline nounwind {
-entry:
- ret <2 x i32*> %v
-}
-
-; Valid cases, only bitcast for argument / return type and call underlying function
-
-; Sizes match, should only bitcast
-define void @bitcast_alias_scalar(float* noalias %source, float* noalias %dest) nounwind {
-entry:
-; CHECK-LABEL: @bitcast_alias_scalar
-; CHECK: bitcast float* %source to i32*
-; CHECK: load i32, i32*
-; CHECK-NOT: fptoui
-; CHECK-NOT: uitofp
-; CHECK: bitcast float* %dest to i32*
-; CHECK: store i32
- %tmp = load float, float* %source, align 8
- %call = call float @alias_i32_to_f32(float %tmp) nounwind
- store float %call, float* %dest, align 8
- ret void
-}
-
-; Sizes match, should only bitcast
-define void @bitcast_alias_vector(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
-entry:
-; CHECK-LABEL: @bitcast_alias_vector
-; CHECK: bitcast <2 x float>* %source to <2 x i32>*
-; CHECK: load <2 x i32>, <2 x i32>*
-; CHECK-NOT: fptoui
-; CHECK-NOT: uitofp
-; CHECK: bitcast <2 x float>* %dest to <2 x i32>*
-; CHECK: store <2 x i32>
- %tmp = load <2 x float>, <2 x float>* %source, align 8
- %call = call <2 x float> @alias_v2i32_to_v2f32(<2 x float> %tmp) nounwind
- store <2 x float> %call, <2 x float>* %dest, align 8
- ret void
-}
-
-; Sizes match, should only bitcast
-define void @bitcast_alias_vector_scalar_same_size(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
-entry:
-; CHECK-LABEL: @bitcast_alias_vector_scalar_same_size
-; CHECK: bitcast <2 x float>* %source to i64*
-; CHECK: load i64, i64*
-; CHECK: %call = call i64 @func_i64
-; CHECK: bitcast <2 x float>* %dest to i64*
-; CHECK: store i64
- %tmp = load <2 x float>, <2 x float>* %source, align 8
- %call = call <2 x float> @alias_v2f32_to_i64(<2 x float> %tmp) nounwind
- store <2 x float> %call, <2 x float>* %dest, align 8
- ret void
-}
-
-define void @bitcast_alias_scalar_vector_same_size(i64* noalias %source, i64* noalias %dest) nounwind {
-entry:
-; CHECK-LABEL: @bitcast_alias_scalar_vector_same_size
-; CHECK: bitcast i64* %source to <2 x float>*
-; CHECK: load <2 x float>, <2 x float>*
-; CHECK: call <2 x float> @func_v2f32
-; CHECK: bitcast i64* %dest to <2 x float>*
-; CHECK: store <2 x float>
- %tmp = load i64, i64* %source, align 8
- %call = call i64 @alias_i64_to_v2f32(i64 %tmp) nounwind
- store i64 %call, i64* %dest, align 8
- ret void
-}
-
-define void @bitcast_alias_vector_ptrs_same_size(<2 x i64*>* noalias %source, <2 x i64*>* noalias %dest) nounwind {
-entry:
-; CHECK-LABEL: @bitcast_alias_vector_ptrs_same_size
-; CHECK: bitcast <2 x i64*>* %source to <2 x i32*>*
-; CHECK: load <2 x i32*>, <2 x i32*>*
-; CHECK: call <2 x i32*> @func_v2i32p
-; CHECK: bitcast <2 x i64*>* %dest to <2 x i32*>*
-; CHECK: store <2 x i32*>
- %tmp = load <2 x i64*>, <2 x i64*>* %source, align 8
- %call = call <2 x i64*> @alias_v2i32p_to_v2i64p(<2 x i64*> %tmp) nounwind
- store <2 x i64*> %call, <2 x i64*>* %dest, align 8
- ret void
-}
-
-; Invalid cases:
-
-define void @bitcast_alias_mismatch_scalar_size(float* noalias %source, float* noalias %dest) nounwind {
-entry:
-; CHECK-LABEL: @bitcast_alias_mismatch_scalar_size
-; CHECK-NOT: fptoui
-; CHECK: @alias_i64_to_f32
-; CHECK-NOT: uitofp
- %tmp = load float, float* %source, align 8
- %call = call float @alias_i64_to_f32(float %tmp) nounwind
- store float %call, float* %dest, align 8
- ret void
-}
-
-define void @bitcast_alias_mismatch_vector_element_and_bit_size(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
-entry:
-; CHECK-LABEL: @bitcast_alias_mismatch_vector_element_and_bit_size
-; CHECK-NOT: fptoui <2 x float> %tmp to <2 x i64>
-; CHECK: @alias_v2i64_to_v2f32
-; CHECK-NOT: uitofp <2 x i64> %call to <2 x float>
- %tmp = load <2 x float>, <2 x float>* %source, align 8
- %call = call <2 x float> @alias_v2i64_to_v2f32(<2 x float> %tmp) nounwind
- store <2 x float> %call, <2 x float>* %dest, align 8
- ret void
-}
-
-define void @bitcast_alias_vector_mismatched_number_elements(<4 x float>* noalias %source, <4 x float>* noalias %dest) nounwind {
-entry:
-; CHECK-LABEL: @bitcast_alias_vector_mismatched_number_elements
-; CHECK: %call = call <4 x float> @alias_v2i32_to_v4f32
- %tmp = load <4 x float>, <4 x float>* %source, align 8
- %call = call <4 x float> @alias_v2i32_to_v4f32(<4 x float> %tmp) nounwind
- store <4 x float> %call, <4 x float>* %dest, align 8
- ret void
-}
-
-define void @bitcast_alias_vector_scalar_mismatched_bit_size(<4 x float>* noalias %source, <4 x float>* noalias %dest) nounwind {
-entry:
-; CHECK-LABEL: @bitcast_alias_vector_scalar_mismatched_bit_size
-; CHECK: %call = call <4 x float> @alias_v4f32_to_i64
- %tmp = load <4 x float>, <4 x float>* %source, align 8
- %call = call <4 x float> @alias_v4f32_to_i64(<4 x float> %tmp) nounwind
- store <4 x float> %call, <4 x float>* %dest, align 8
- ret void
-}
-
-define void @bitcast_alias_vector_ptrs_scalar_mismatched_bit_size(<4 x i32*>* noalias %source, <4 x i32*>* noalias %dest) nounwind {
-entry:
-; CHECK-LABEL: @bitcast_alias_vector_ptrs_scalar_mismatched_bit_size
-; CHECK: @alias_v4i32p_to_i64
- %tmp = load <4 x i32*>, <4 x i32*>* %source, align 8
- %call = call <4 x i32*> @alias_v4i32p_to_i64(<4 x i32*> %tmp) nounwind
- store <4 x i32*> %call, <4 x i32*>* %dest, align 8
- ret void
-}
-
-define void @bitcast_alias_scalar_vector_ptrs_same_size(i64* noalias %source, i64* noalias %dest) nounwind {
-entry:
-; CHECK-LABEL: @bitcast_alias_scalar_vector_ptrs_same_size
-; CHECK: @alias_i64_to_v2i32p
- %tmp = load i64, i64* %source, align 8
- %call = call i64 @alias_i64_to_v2i32p(i64 %tmp) nounwind
- store i64 %call, i64* %dest, align 8
- ret void
-}
-
-define void @bitcast_alias_scalar_vector_mismatched_bit_size(i64* noalias %source, i64* noalias %dest) nounwind {
-entry:
-; CHECK-LABEL: @bitcast_alias_scalar_vector_mismatched_bit_size
-; CHECK: call i64 @alias_i64_to_v4f32
- %tmp = load i64, i64* %source, align 8
- %call = call i64 @alias_i64_to_v4f32(i64 %tmp) nounwind
- store i64 %call, i64* %dest, align 8
- ret void
-}
-
diff --git a/llvm/test/Transforms/InstCombine/bitcast-function.ll b/llvm/test/Transforms/InstCombine/bitcast-function.ll
new file mode 100644
index 00000000000..ca82165a49c
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/bitcast-function.ll
@@ -0,0 +1,206 @@
+; RUN: opt -S -instcombine -o - %s | FileCheck %s
+target datalayout = "e-p:32:32:32-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v64:64:64-v128:128:128-a0:0:64"
+
+define internal <2 x i32> @func_v2i32(<2 x i32> %v) noinline nounwind {
+entry:
+ ret <2 x i32> %v
+}
+
+define internal <2 x float> @func_v2f32(<2 x float> %v) noinline nounwind {
+entry:
+ ret <2 x float> %v
+}
+
+define internal <4 x float> @func_v4f32(<4 x float> %v) noinline nounwind {
+entry:
+ ret <4 x float> %v
+}
+
+define internal i32 @func_i32(i32 %v) noinline nounwind {
+entry:
+ ret i32 %v
+}
+
+define internal i64 @func_i64(i64 %v) noinline nounwind {
+entry:
+ ret i64 %v
+}
+
+define internal <2 x i64> @func_v2i64(<2 x i64> %v) noinline nounwind {
+entry:
+ ret <2 x i64> %v
+}
+
+define internal <2 x i32*> @func_v2i32p(<2 x i32*> %v) noinline nounwind {
+entry:
+ ret <2 x i32*> %v
+}
+
+; Valid cases, only bitcast for argument / return type and call underlying function
+
+; Test cast between scalars with same bit sizes
+; Sizes match, should only bitcast
+define void @bitcast_scalar(float* noalias %source, float* noalias %dest) nounwind {
+entry:
+; CHECK-LABEL: @bitcast_scalar
+; CHECK: bitcast float* %source to i32*
+; CHECK: load i32, i32*
+; CHECK-NOT: fptoui
+; CHECK-NOT: uitofp
+; CHECK: bitcast float* %dest to i32*
+; CHECK: store i32
+ %tmp = load float, float* %source, align 8
+ %call = call float bitcast (i32 (i32)* @func_i32 to float (float)*)(float %tmp) nounwind
+ store float %call, float* %dest, align 8
+ ret void
+}
+
+; Test cast between vectors with same number of elements and bit sizes
+; Sizes match, should only bitcast
+define void @bitcast_vector(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
+entry:
+; CHECK-LABEL: @bitcast_vector
+; CHECK: bitcast <2 x float>* %source to <2 x i32>*
+; CHECK: load <2 x i32>, <2 x i32>*
+; CHECK-NOT: fptoui
+; CHECK-NOT: uitofp
+; CHECK: bitcast <2 x float>* %dest to <2 x i32>*
+; CHECK: store <2 x i32>
+ %tmp = load <2 x float>, <2 x float>* %source, align 8
+ %call = call <2 x float> bitcast (<2 x i32> (<2 x i32>)* @func_v2i32 to <2 x float> (<2 x float>)*)(<2 x float> %tmp) nounwind
+ store <2 x float> %call, <2 x float>* %dest, align 8
+ ret void
+}
+
+; Test cast from vector to scalar with same number of bits
+; Sizes match, should only bitcast
+define void @bitcast_vector_scalar_same_size(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
+entry:
+; CHECK-LABEL: @bitcast_vector_scalar_same_size
+; CHECK: bitcast <2 x float>* %source to i64*
+; CHECK: load i64, i64*
+; CHECK: %call = call i64 @func_i64
+; CHECK: bitcast <2 x float>* %dest to i64*
+; CHECK: store i64
+ %tmp = load <2 x float>, <2 x float>* %source, align 8
+ %call = call <2 x float> bitcast (i64 (i64)* @func_i64 to <2 x float> (<2 x float>)*)(<2 x float> %tmp) nounwind
+ store <2 x float> %call, <2 x float>* %dest, align 8
+ ret void
+}
+
+; Test cast from scalar to vector with same number of bits
+define void @bitcast_scalar_vector_same_size(i64* noalias %source, i64* noalias %dest) nounwind {
+entry:
+; CHECK-LABEL: @bitcast_scalar_vector_same_size
+; CHECK: bitcast i64* %source to <2 x float>*
+; CHECK: load <2 x float>, <2 x float>*
+; CHECK: call <2 x float> @func_v2f32
+; CHECK: bitcast i64* %dest to <2 x float>*
+; CHECK: store <2 x float>
+ %tmp = load i64, i64* %source, align 8
+ %call = call i64 bitcast (<2 x float> (<2 x float>)* @func_v2f32 to i64 (i64)*)(i64 %tmp) nounwind
+ store i64 %call, i64* %dest, align 8
+ ret void
+}
+
+; Test cast between vectors of pointers
+define void @bitcast_vector_ptrs_same_size(<2 x i64*>* noalias %source, <2 x i64*>* noalias %dest) nounwind {
+entry:
+; CHECK-LABEL: @bitcast_vector_ptrs_same_size
+; CHECK: bitcast <2 x i64*>* %source to <2 x i32*>*
+; CHECK: load <2 x i32*>, <2 x i32*>*
+; CHECK: call <2 x i32*> @func_v2i32p
+; CHECK: bitcast <2 x i64*>* %dest to <2 x i32*>*
+; CHECK: store <2 x i32*>
+ %tmp = load <2 x i64*>, <2 x i64*>* %source, align 8
+ %call = call <2 x i64*> bitcast (<2 x i32*> (<2 x i32*>)* @func_v2i32p to <2 x i64*> (<2 x i64*>)*)(<2 x i64*> %tmp) nounwind
+ store <2 x i64*> %call, <2 x i64*>* %dest, align 8
+ ret void
+}
+
+; Invalid cases:
+
+; Test cast between scalars with different bit sizes
+define void @bitcast_mismatch_scalar_size(float* noalias %source, float* noalias %dest) nounwind {
+entry:
+; CHECK-LABEL: @bitcast_mismatch_scalar_size
+; CHECK-NOT: fptoui
+; CHECK: call float bitcast
+; CHECK-NOT: uitofp
+ %tmp = load float, float* %source, align 8
+ %call = call float bitcast (i64 (i64)* @func_i64 to float (float)*)(float %tmp) nounwind
+ store float %call, float* %dest, align 8
+ ret void
+}
+
+; Test cast between vectors with different bit sizes but the
+; same number of elements
+define void @bitcast_mismatch_vector_element_and_bit_size(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
+entry:
+; CHECK-LABEL: @bitcast_mismatch_vector_element_and_bit_size
+; CHECK-NOT: fptoui <2 x float> %tmp to <2 x i64>
+; CHECK: call <2 x float> bitcast
+; CHECK-NOT: uitofp <2 x i64> %call to <2 x float>
+ %tmp = load <2 x float>, <2 x float>* %source, align 8
+ %call = call <2 x float> bitcast (<2 x i64> (<2 x i64>)* @func_v2i64 to <2 x float> (<2 x float>)*)(<2 x float> %tmp) nounwind
+ store <2 x float> %call, <2 x float>* %dest, align 8
+ ret void
+}
+
+; Test cast between vectors with same number of bits and different
+; numbers of elements
+define void @bitcast_vector_mismatched_number_elements(<4 x float>* noalias %source, <4 x float>* noalias %dest) nounwind {
+entry:
+; CHECK-LABEL: @bitcast_vector_mismatched_number_elements
+; CHECK: %call = call <4 x float> bitcast
+ %tmp = load <4 x float>, <4 x float>* %source, align 8
+ %call = call <4 x float> bitcast (<2 x i32> (<2 x i32>)* @func_v2i32 to <4 x float> (<4 x float>)*)(<4 x float> %tmp) nounwind
+ store <4 x float> %call, <4 x float>* %dest, align 8
+ ret void
+}
+
+; Test cast between vector and scalar with different number of bits
+define void @bitcast_vector_scalar_mismatched_bit_size(<4 x float>* noalias %source, <4 x float>* noalias %dest) nounwind {
+entry:
+; CHECK-LABEL: @bitcast_vector_scalar_mismatched_bit_size
+; CHECK: %call = call <4 x float> bitcast
+ %tmp = load <4 x float>, <4 x float>* %source, align 8
+ %call = call <4 x float> bitcast (i64 (i64)* @func_i64 to <4 x float> (<4 x float>)*)(<4 x float> %tmp) nounwind
+ store <4 x float> %call, <4 x float>* %dest, align 8
+ ret void
+}
+
+; Test cast between vector of pointers and scalar with different number of bits
+define void @bitcast_vector_ptrs_scalar_mismatched_bit_size(<4 x i32*>* noalias %source, <4 x i32*>* noalias %dest) nounwind {
+entry:
+; CHECK-LABEL: @bitcast_vector_ptrs_scalar_mismatched_bit_size
+; CHECK: call <4 x i32*> bitcast
+ %tmp = load <4 x i32*>, <4 x i32*>* %source, align 8
+ %call = call <4 x i32*> bitcast (i64 (i64)* @func_i64 to <4 x i32*> (<4 x i32*>)*)(<4 x i32*> %tmp) nounwind
+ store <4 x i32*> %call, <4 x i32*>* %dest, align 8
+ ret void
+}
+
+; Test cast from scalar to vector of pointers with same number of bits
+; We don't know the pointer size at this point, so this can't be done
+define void @bitcast_scalar_vector_ptrs_same_size(i64* noalias %source, i64* noalias %dest) nounwind {
+entry:
+; CHECK-LABEL: @bitcast_scalar_vector_ptrs_same_size
+; CHECK: call i64 bitcast
+ %tmp = load i64, i64* %source, align 8
+ %call = call i64 bitcast (<2 x i32*> (<2 x i32*>)* @func_v2i32p to i64 (i64)*)(i64 %tmp) nounwind
+ store i64 %call, i64* %dest, align 8
+ ret void
+}
+
+; Test cast between scalar and vector with different number of bits
+define void @bitcast_scalar_vector_mismatched_bit_size(i64* noalias %source, i64* noalias %dest) nounwind {
+entry:
+; CHECK-LABEL: @bitcast_scalar_vector_mismatched_bit_size
+; CHECK: call i64 bitcast
+ %tmp = load i64, i64* %source, align 8
+ %call = call i64 bitcast (<4 x float> (<4 x float>)* @func_v4f32 to i64 (i64)*)(i64 %tmp) nounwind
+ store i64 %call, i64* %dest, align 8
+ ret void
+}
+
diff --git a/llvm/test/Transforms/InstCombine/gep-alias.ll b/llvm/test/Transforms/InstCombine/gep-alias.ll
new file mode 100644
index 00000000000..890b61688cf
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/gep-alias.ll
@@ -0,0 +1,15 @@
+; RUN: opt -S -instcombine -o - %s | FileCheck %s
+
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64-unknown-linux-android10000"
+
+@x.hwasan = private global { [3 x i32], [4 x i8] } { [3 x i32] [i32 42, i32 57, i32 10], [4 x i8] c"\00\00\00\87" }, align 16
+@x = alias [3 x i32], inttoptr (i64 add (i64 ptrtoint ({ [3 x i32], [4 x i8] }* @x.hwasan to i64), i64 -8718968878589280256) to [3 x i32]*)
+
+define i32 @f(i64 %i) {
+entry:
+ ; CHECK: getelementptr inbounds [3 x i32], [3 x i32]* @x
+ %arrayidx = getelementptr inbounds [3 x i32], [3 x i32]* @x, i64 0, i64 %i
+ %0 = load i32, i32* %arrayidx
+ ret i32 %0
+}
diff --git a/llvm/test/Transforms/InstCombine/pr39177.ll b/llvm/test/Transforms/InstCombine/pr39177.ll
index 35c5ce0d3f6..c0f0e860439 100644
--- a/llvm/test/Transforms/InstCombine/pr39177.ll
+++ b/llvm/test/Transforms/InstCombine/pr39177.ll
@@ -30,7 +30,7 @@ define void @foo() {
; CHECK-LABEL: @foo(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = load %struct._IO_FILE*, %struct._IO_FILE** @stderr, align 8
-; CHECK-NEXT: [[TMP1:%.*]] = call i64 @__fwrite_alias(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 7, i64 1, %struct._IO_FILE* [[TMP0]])
+; CHECK-NEXT: [[TMP1:%.*]] = call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 7, i64 1, %struct._IO_FILE* [[TMP0]])
; CHECK-NEXT: ret void
;
entry:
OpenPOWER on IntegriCloud