Last use of operand within BasicBlock?

Given an instruction and the basic block that it’s in, is there an easy way to tell if the operands are ever referenced after the instruction?

For example, if i have

%mul = mul nsw i32 %a, %val
%add = add nsw i32 %b, %val

And I’m iterating through this basic block, can I tell when I get to the multiply instruction that another instruction is going to be using %val?

Since I’m running my code through reg2mem, I don’t really care much about other basicblocks (anything outside the basicblock should have an eliminated phi instruction so it will be pulled from memory anyways).

Hi Ryan,

Given an instruction and the basic block that it's in, is there an easy way to
tell if the operands are ever referenced after the instruction?

if the operand only has one use (->hasOneUse()) then you know it. Otherwise it
is more tricky. Why do you care?

Ciao, Duncan.