[PATCH] [InstCombine] Canonicalize min/max expressions correctly.
David Majnemer
david.majnemer at gmail.com
Wed May 13 23:49:30 PDT 2015
REPOSITORY
rL LLVM
================
Comment at: lib/Transforms/InstCombine/InstCombineSelect.cpp:1169-1176
@@ +1168,10 @@
+ SI.getType()->getPrimitiveSizeInBits()) {
+ CmpInst::Predicate Pred;
+ switch (SPF) {
+ case SPF_SMIN: Pred = CmpInst::ICMP_SLT; break;
+ case SPF_SMAX: Pred = CmpInst::ICMP_SGT; break;
+ case SPF_UMIN: Pred = CmpInst::ICMP_ULT; break;
+ case SPF_UMAX: Pred = CmpInst::ICMP_UGT; break;
+ default: llvm_unreachable("Unknown SPF type!");
+ }
+ return CastInst::Create(CastOp,
----------------
This looks the same as `getICmpPredicateForMinMax`.
================
Comment at: lib/Transforms/InstCombine/InstCombineSelect.cpp:1177-1182
@@ +1176,8 @@
+ }
+ return CastInst::Create(CastOp,
+ SelectInst::Create(
+ CmpInst::Create(Instruction::ICmp, Pred,
+ LHS, RHS, "", &SI),
+ LHS, RHS, "", &SI),
+ SI.getType());
+ }
----------------
I'd expect you to use the IRBuilder to construct each instruction up until the last which I'd expect you'd feed into `ReplaceInstUsesWith`.
http://reviews.llvm.org/D9749
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the llvm-commits
mailing list