[llvm-dev] Possible bug in llvm::EmitGEPOffset
Francois Pichet via llvm-dev
llvm-dev at lists.llvm.org
Wed Aug 21 20:01:13 PDT 2019
I am investigating a bad codegen bug for an out-of-tree target.
I found out that llvm::EmitGEPOffset (file include\llvm\Analysis\Utils)
will create a mul with nuw flag if the GEP isInBounds is true:
Op = Builder->CreateMul(Op, ConstantInt::get(IntPtrTy, Size),
GEP->getName()+".idx", isInBounds /*NUW*/);
But what if Op is a variable that contains a negative number. In that case
the nuw flag is wrong right?
Because the mul will eventually be changed to
%101 = shl nuw i32 %93, 2
%93 being a variable holding a negative value (clearly the 2 high bit are
This will cause a miscompile eventually.
I think llvm::EmitGEPOffset is being too aggressive in setting nuw here.
Or am I missing something?
(I fixed the problem locally by calling EmitGEPOffset with NoAssumptions =
true) in InstructionCombining.cpp)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev