<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<div name="messageBodySection">
<div dir="auto">Hello,
<div dir="auto"><br>
</div>
<div dir="auto">To play around with, I duplicated the branch instruction implementation in LLVM and Clang under the opcode ‘fbr’ as opposed to regular ‘br’. I accept LLVM to accept the new opcode and have Clang produce ‘fbr’ branches instead of the normal branches.
 But the place of ‘if.then' and ‘if.else' in the instruction is switch. Instead of if.then occurring first, if.else is occurring first. For example:</div>
<div dir="auto"><br>
</div>
<div dir="auto">  The normal conditional branch instructions would be: "<span style="color: var(--textColor); background-color: var(--backgroundColor);">br i1 %cmp, label %if.then, label %if.else”</span></div>
<div dir="auto"><span style="color: var(--textColor); background-color: var(--backgroundColor);">  But if I force Clang to produce ’fbr’ instruction, it becomes: “f</span><span style="color: var(--textColor); background-color: var(--backgroundColor);">br i1
 %cmp, label %if.else, label %if.then” (the condition doesn’t inverse either)</span></div>
<div dir="auto"><br>
</div>
<div dir="auto">This is causing the output to the wrong since the right and wrong block are switched. I traced it down to the generation of the custom branch instruction to Instructions.cpp (it’s the same as BranchstInst class but just the opcode changed) and
 dumping all the information once it’s being created. Everything is in order until it returns back from FBranchInst::Create (in IRBuilder.h), which is where the if.then and if.else are being switch. I have no idea what’s causing it to flip, and what makes it
 weird is that if I pass the .ll file to opt (or back it back into Clang with -emit-llvm option), the new output file has the block order flipped back (so if.then is first and following that is if.else). They flip to the wrong order if I pass it back through
 opt (or Clang) again.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Could I have missed to duplicate something from BranchInst that might be causing this? I’d appreciate any help I could get with this.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Sincerely,</div>
<div dir="auto">Kaarthik A.</div>
</div>
</div>
</body>
</html>