[llvm] r265367 - Don't fold double constant to an integer if dest type not integral
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 4 16:50:46 PDT 2016
Author: tejohnson
Date: Mon Apr 4 18:50:46 2016
New Revision: 265367
URL: http://llvm.org/viewvc/llvm-project?rev=265367&view=rev
Log:
Don't fold double constant to an integer if dest type not integral
Summary:
I encountered this issue when constant folding during inlining tried to
fold away a bitcast of a double to an x86_mmx, which is not an integral
type. The test case exposes the same issue with a smaller code snippet
during early CSE.
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D18528
Added:
llvm/trunk/test/CodeGen/X86/mmx-bitcast-fold.ll
Modified:
llvm/trunk/lib/IR/ConstantFold.cpp
Modified: llvm/trunk/lib/IR/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=265367&r1=265366&r2=265367&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp (original)
+++ llvm/trunk/lib/IR/ConstantFold.cpp Mon Apr 4 18:50:46 2016
@@ -191,6 +191,10 @@ static Constant *FoldBitCast(Constant *V
if (FP->getType()->isPPC_FP128Ty())
return nullptr;
+ // Make sure dest type is compatible with the folded integer constant.
+ if (!DestTy->isIntegerTy())
+ return nullptr;
+
return ConstantInt::get(FP->getContext(),
FP->getValueAPF().bitcastToAPInt());
}
Added: llvm/trunk/test/CodeGen/X86/mmx-bitcast-fold.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/mmx-bitcast-fold.ll?rev=265367&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/mmx-bitcast-fold.ll (added)
+++ llvm/trunk/test/CodeGen/X86/mmx-bitcast-fold.ll Mon Apr 4 18:50:46 2016
@@ -0,0 +1,12 @@
+; RUN: opt -mtriple=x86_64-- -early-cse < %s -S | FileCheck %s
+
+; CHECK: @foo(x86_mmx bitcast (double 0.000000e+00 to x86_mmx))
+
+define void @bar() {
+entry:
+ %0 = bitcast double 0.0 to x86_mmx
+ %1 = call x86_mmx @foo(x86_mmx %0)
+ ret void
+}
+
+declare x86_mmx @foo(x86_mmx)
More information about the llvm-commits
mailing list