[llvm] 65bec04 - [ConstantFold] Handle same type in ConstantFoldLoadThroughBitcast
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 10 07:39:58 PST 2021
Author: Nikita Popov
Date: 2021-12-10T16:39:50+01:00
New Revision: 65bec04295f1f678977151454ce852ba61149ac8
URL: https://github.com/llvm/llvm-project/commit/65bec04295f1f678977151454ce852ba61149ac8
DIFF: https://github.com/llvm/llvm-project/commit/65bec04295f1f678977151454ce852ba61149ac8.diff
LOG: [ConstantFold] Handle same type in ConstantFoldLoadThroughBitcast
Usually the case where the types are the same ends up being handled
fine because it's legal to do a trivial bitcast to the same type.
However, this is not true for aggregate types. Short-circuit the
whole code if the types match exactly to account for this.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 9324463b4b1fa..fcf4be4a538bc 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -352,6 +352,9 @@ Constant *llvm::ConstantFoldLoadThroughBitcast(Constant *C, Type *DestTy,
const DataLayout &DL) {
do {
Type *SrcTy = C->getType();
+ if (SrcTy == DestTy)
+ return C;
+
TypeSize DestSize = DL.getTypeSizeInBits(DestTy);
TypeSize SrcSize = DL.getTypeSizeInBits(SrcTy);
if (!TypeSize::isKnownGE(SrcSize, DestSize))
diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll b/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
index adde18135a964..0938078dc47ba 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
@@ -275,8 +275,7 @@ define {}* @test_trailing_zero_gep_index() {
define { i64, i64 } @test_load_struct() {
; CHECK-LABEL: @test_load_struct(
-; CHECK-NEXT: [[V:%.*]] = load { i64, i64 }, { i64, i64 }* @g3, align 8
-; CHECK-NEXT: ret { i64, i64 } [[V]]
+; CHECK-NEXT: ret { i64, i64 } { i64 123, i64 112312312 }
;
%v = load { i64, i64 }, { i64, i64 }* @g3
ret { i64, i64 } %v
More information about the llvm-commits
mailing list