[llvm] r191668 - Fix a bug in InstCombine where it attempted to cast a Value* to an Instruction*
Joey Gouly
joey.gouly at arm.com
Wed Oct 2 03:00:49 PDT 2013
Ben Kramer committed r191673 and r191674, which should fix this by using an
RAII object, so the flags don't need to be set manually.
-----Original Message-----
From: Bob Wilson [mailto:bob.wilson at apple.com]
Sent: 01 October 2013 19:40
To: Shuxin Yang
Cc: Joey Gouly; Commit Messages and Patches for LLVM
Subject: Re: [llvm] r191668 - Fix a bug in InstCombine where it attempted to
cast a Value* to an Instruction*
Can one of you please audit the other casts and fix any of them with the
same problem?
On Oct 1, 2013, at 11:03 AM, Shuxin Yang <shuxin.llvm at gmail.com> wrote:
> Thanks! That is my bug:-)
>> Author: joey
>> Date: Mon Sep 30 09:18:35 2013
>> New Revision: 191668
>>
>> URL:http://llvm.org/viewvc/llvm-project?rev=191668&view=rev
>> Log:
>> 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.
>>
>> Modified:
>> llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
>> llvm/trunk/test/Transforms/InstCombine/fmul.ll
>>
>> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
>>
URL:http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombin
e/InstCombineMulDivRem.cpp?rev=191668&r1=191667&r2=191668&view=diff
>>
============================================================================
==
>> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
(original)
>> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Mon
Sep 30 09:18:35 2013
>> @@ -519,10 +519,10 @@ Instruction *InstCombiner::visitFMul(Bin
>> 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;
>>
>> Modified: llvm/trunk/test/Transforms/InstCombine/fmul.ll
>>
URL:http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombi
ne/fmul.ll?rev=191668&r1=191667&r2=191668&view=diff
>>
============================================================================
==
>> --- llvm/trunk/test/Transforms/InstCombine/fmul.ll (original)
>> +++ llvm/trunk/test/Transforms/InstCombine/fmul.ll Mon Sep 30 09:18:35
2013
>> @@ -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
>> +}
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list