<div dir="ltr">I doubt InstCombine is looking specifically for the name _Znwm. What's going to be important to InstCombine is the attributes on the declaration/definition of _Znwm in the IR and the attributes on the call instruction. Can you provide those?<div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 29, 2021 at 3:41 PM Stephen Long via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I have the following IR:<br>
<br>
; Function Attrs: norecurse uwtable<br>
define dso_local i32 @main() #6 {<br>
entry:<br>
  %a = alloca %"class.std::__1::allocator", align 1<br>
  %0 = bitcast %"class.std::__1::allocator"* %a to i8*<br>
  call void @llvm.lifetime.start.p0i8(i64 1, i8* %0) #13<br>
  %call.i.i.i = call noalias nonnull i8* @_Znwm(i64 1) #15<br>
  %1 = bitcast i8* %call.i.i.i to %struct.A*<br>
  %2 = load volatile i8, i8* @global, align 1, !tbaa !12, !range !16<br>
  %tobool = trunc i8 %2 to i1<br>
  %selv = select i1 %tobool, i32 0, i32 1<br>
  call void @llvm.lifetime.end.p0i8(i64 1, i8* %0) #13<br>
  ret i32 %selv<br>
}<br>
<br>
I ran the InstCombine pass on it with opt and it seems like LLVM is optimizing out the _Znwm call. My overloaded new operator has a side effect which is setting the global variable to 1.<br>
Is InstCombine allowed to just get rid of the new() call, even though there is a side effect?<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>