1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00

Fix a bug in InstCombine where it attempted to cast a Value* to an Instruction*

when it was actually a Constant*.

There are quite a few other casts to Instruction that might have the same problem,
but this is the only one I have a test case for.

llvm-svn: 191668
This commit is contained in:
Joey Gouly 2013-09-30 14:18:35 +00:00
parent d1b1de4b4c
commit b2a84bfcc1
2 changed files with 25 additions and 2 deletions

View File

@ -519,10 +519,10 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
if (Opnd0->hasOneUse()) {
// -X * Y => -(X*Y) (Promote negation as high as possible)
Value *T = Builder->CreateFMul(N0, Opnd1);
cast<Instruction>(T)->setDebugLoc(I.getDebugLoc());
Instruction *Neg = BinaryOperator::CreateFNeg(T);
if (I.getFastMathFlags().any()) {
cast<Instruction>(T)->copyFastMathFlags(&I);
if (Instruction *TI = dyn_cast<Instruction>(T))
TI->copyFastMathFlags(&I);
Neg->copyFastMathFlags(&I);
}
return Neg;

View File

@ -70,3 +70,26 @@ define float @test7(float %x, float %y) {
; CHECK-LABEL: @test7(
; CHECK: fsub float -0.000000e+00, %x
}
; Don't crash when attempting to cast a constant FMul to an instruction.
define void @test8(i32* %inout) {
entry:
%0 = load i32* %inout, align 4
%conv = uitofp i32 %0 to float
%vecinit = insertelement <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float undef>, float %conv, i32 3
%sub = fsub <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %vecinit
%1 = shufflevector <4 x float> %sub, <4 x float> undef, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
%mul = fmul <4 x float> zeroinitializer, %1
br label %for.cond
for.cond: ; preds = %for.body, %entry
%local_var_7.0 = phi <4 x float> [ %mul, %entry ], [ %2, %for.body ]
br i1 undef, label %for.body, label %for.end
for.body: ; preds = %for.cond
%2 = insertelement <4 x float> %local_var_7.0, float 0.000000e+00, i32 2
br label %for.cond
for.end: ; preds = %for.cond
ret void
}