This is an archive of the discontinued LLVM Phabricator instance.

[IRBuilder] Add CreateUnOp(...) and CreateFNegFMF(...)
AbandonedPublic

Authored by cameron.mcinally on May 23 2019, 5:06 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2019, 5:06 PM
craig.topper added inline comments.May 23 2019, 5:21 PM
llvm/include/llvm/IR/IRBuilder.h
1369

Why can't this keep using Folder.CreateFNeg? CreateNot uses Folder.CreateNot.

craig.topper added inline comments.May 23 2019, 5:24 PM
llvm/include/llvm/IR/IRBuilder.h
1379

It feels weird that this creates unaryoperator::fneg but CreateFNeg uses the binaryoperator. Shouldn't these be consistent until we switch over?

llvm/include/llvm/IR/IRBuilder.h
1369

I considered this also and went with something more like CreateBinOp (see CreateUnOp too). The UnOps are odd ducks since they’re not really unary operators, but rather they’re implemented with existing BinOps. IMO, we should be moving away from the weirdness of the UnOps...

I don’t feel very strongly about this though. If you think the current UnOp direction is better, that’s fine with me.

1379

So I did consider that. My thinking was that we wouldn’t be regressing calling the UnaryOperator here, since it’s brand new code, so it’s better to move towards the goal. The reason we haven’t updated the old BinaryOperator code yet is that we’re afraid of regressions.

I do see your point though...

Also, let me be clear that this function will have at least one use in a patch to come. I’ve just broken out this digestible chunk for now.

llvm/include/llvm/IR/IRBuilder.h
1369

Oh oh, I just remembered why I went down the BinOps path. If I’m not mistaken, the Folder.CreateFNeg method throws away FMF when there’s no folder. I wanted to avoid that. I’ll confirm in the morning...

cameron.mcinally marked 2 inline comments as done.May 24 2019, 8:31 AM
cameron.mcinally added inline comments.
llvm/include/llvm/IR/IRBuilder.h
1369

If I’m not mistaken, the Folder.CreateFNeg method throws away FMF when there’s no folder.

I confused myself. That is a problem, but it's not this problem. In general, when the NoFolder is used, the new CreateF*FMF(...) instruction picks up the default FMFs from the IRBuilder, not the instruction it's supposed to copy from.

So, yeah, I could change this code back to make it look more like CreateNot, if that's the preference.

llvm/unittests/IR/PatternMatch.cpp
641

Just realized I misplaced these tests, so I'll have to update them.

cameron.mcinally abandoned this revision.May 24 2019, 11:20 AM

Moving the test ended up being a can of worms. I'm going to abandon this Diff to split it into two...