Sanjay Patel
2014-Sep-18 21:25 UTC
[LLVMdev] predicates vs. requirements [TableGen, X86InstrInfo.td]
I tried to add an 'OptForSize' requirement to a pattern in X86InstrSSE.td, but it appears to be ignored. However, the condition was detected when specified as a predicate. So this doesn't work: def : Pat<(v2f64 (X86VBroadcast (loadf64 addr:$src))), (VMOVDDUPrm addr: $src)>, *Requires<[OptForSize**]>*; But this does: * let Predicates = [OptForSize] in* { def : Pat<(v2f64 (X86VBroadcast (loadf64 addr:$src))), (VMOVDDUPrm addr :$src)>; } I see both forms used on some patterns like this: * let Predicates = [HasAVX] *in { def : Pat<(X86Movddup (loadv2f64 addr:$src)), (VMOVDDUPrm addr:$src)>, *Requires<[HasAVX]>*; } Is a predicate different than a requirement or is this a bug? There are existing patterns that specify 'OptForSize' with "Requires", but they are not behaving as I expected. Example: // For scalar unary operations, fold a load into the operation // only in OptForSize mode. It eliminates an instruction, but it also // eliminates a whole-register clobber (the load), so it introduces a // partial register update condition. def : Pat<(f32 (fsqrt (load addr:$src))), (VSQRTSSm (f32 (IMPLICIT_DEF)), addr:$src)>, Requires<[HasAVX, OptForSize]>; This is generated: vsqrtss (%rdi), %xmm0, %xmm0 regardless of whether I specify -Os or -O1 with clang. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140918/3a04abe2/attachment.html>
Hal Finkel
2014-Sep-18 21:40 UTC
[LLVMdev] predicates vs. requirements [TableGen, X86InstrInfo.td]
----- Original Message -----> From: "Sanjay Patel" <spatel at rotateright.com> > To: llvmdev at cs.uiuc.edu > Sent: Thursday, September 18, 2014 4:25:07 PM > Subject: [LLVMdev] predicates vs. requirements [TableGen, X86InstrInfo.td] > > > > > I tried to add an 'OptForSize' requirement to a pattern in > X86InstrSSE.td, but it appears to be ignored. However, the condition > was detected when specified as a predicate.Without looking at this in detail, I've seen similar behavior before, so I'll guess: When you use Requires with OptForSize, it will add OptForSize to the Predicates list, but it will not do so if you explicitly set the Predicates list (with a let clause). So if there are any other predicates in effect, the Requires will be ignored. However, if you explicitly set Predicates (with the let clause) you're erasing any other predicates that may have been in effect from an outer block. -Hal> > So this doesn't work: > def : Pat <( v2f64 ( X86VBroadcast ( loadf64 addr : $src ))), ( > VMOVDDUPrm addr : $src )>, > Requires <[ OptForSize ]> ; > > But this does: > let Predicates = [OptForSize] in { > def : Pat <( v2f64 ( X86VBroadcast ( loadf64 addr : $src ))), ( > VMOVDDUPrm addr : $src )>; > } > > > I see both forms used on some patterns like this: > let Predicates = [HasAVX] in { > def : Pat<(X86Movddup (loadv2f64 addr:$src)), > (VMOVDDUPrm addr:$src)>, Requires<[HasAVX]> ; > } > > > Is a predicate different than a requirement or is this a bug? > > > There are existing patterns that specify 'OptForSize' with > "Requires", but they are not behaving as I expected. > > Example: > // For scalar unary operations, fold a load into the operation > // only in OptForSize mode. It eliminates an instruction, but it also > // eliminates a whole-register clobber (the load), so it introduces a > // partial register update condition. > def : Pat<(f32 (fsqrt (load addr:$src))), > (VSQRTSSm (f32 (IMPLICIT_DEF)), addr:$src)>, > Requires<[HasAVX, OptForSize]>; > > > This is generated: > > vsqrtss (%rdi), %xmm0, %xmm0 > > > regardless of whether I specify -Os or -O1 with clang. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- Hal Finkel Assistant Computational Scientist Leadership Computing Facility Argonne National Laboratory
Tom Stellard
2014-Sep-19 00:35 UTC
[LLVMdev] predicates vs. requirements [TableGen, X86InstrInfo.td]
On Thu, Sep 18, 2014 at 03:25:07PM -0600, Sanjay Patel wrote:> I tried to add an 'OptForSize' requirement to a pattern in X86InstrSSE.td, > but it appears to be ignored. However, the condition was detected when > specified as a predicate. > > So this doesn't work: > def : Pat<(v2f64 (X86VBroadcast (loadf64 addr:$src))), (VMOVDDUPrm addr: > $src)>, > *Requires<[OptForSize**]>*; > > But this does: > * let Predicates = [OptForSize] in* { > def : Pat<(v2f64 (X86VBroadcast (loadf64 addr:$src))), (VMOVDDUPrm addr > :$src)>; > } > > I see both forms used on some patterns like this: > * let Predicates = [HasAVX] *in { > def : Pat<(X86Movddup (loadv2f64 addr:$src)), > (VMOVDDUPrm addr:$src)>, *Requires<[HasAVX]>*; > } > > Is a predicate different than a requirement or is this a bug? > > There are existing patterns that specify 'OptForSize' with "Requires", but > they are not behaving as I expected. > > Example: > // For scalar unary operations, fold a load into the operation > // only in OptForSize mode. It eliminates an instruction, but it also > // eliminates a whole-register clobber (the load), so it introduces a > // partial register update condition. > def : Pat<(f32 (fsqrt (load addr:$src))), > (VSQRTSSm (f32 (IMPLICIT_DEF)), addr:$src)>, > Requires<[HasAVX, OptForSize]>; > > This is generated: > vsqrtss (%rdi), %xmm0, %xmm0 > > regardless of whether I specify -Os or -O1 with clang.You might want to take a look at the Mips target, it has a class called PredicateControl defined in Mips.td, which handles merging predicates together into a single list. Maybe you could do something similar for x86. -Tom> _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Daniel Sanders
2014-Sep-19 10:34 UTC
[LLVMdev] predicates vs. requirements [TableGen, X86InstrInfo.td]
> -----Original Message----- > From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] > On Behalf Of Tom Stellard > Sent: 19 September 2014 01:36 > To: Sanjay Patel > Cc: llvmdev at cs.uiuc.edu > Subject: Re: [LLVMdev] predicates vs. requirements [TableGen, > X86InstrInfo.td] > > On Thu, Sep 18, 2014 at 03:25:07PM -0600, Sanjay Patel wrote: > > I tried to add an 'OptForSize' requirement to a pattern in X86InstrSSE.td, > > but it appears to be ignored. However, the condition was detected when > > specified as a predicate. > > > > So this doesn't work: > > def : Pat<(v2f64 (X86VBroadcast (loadf64 addr:$src))), (VMOVDDUPrm > addr: > > $src)>, > > *Requires<[OptForSize**]>*; > > > > But this does: > > * let Predicates = [OptForSize] in* { > > def : Pat<(v2f64 (X86VBroadcast (loadf64 addr:$src))), (VMOVDDUPrm > addr > > :$src)>; > > } > > > > I see both forms used on some patterns like this: > > * let Predicates = [HasAVX] *in { > > def : Pat<(X86Movddup (loadv2f64 addr:$src)), > > (VMOVDDUPrm addr:$src)>, *Requires<[HasAVX]>*; > > } > > > > Is a predicate different than a requirement or is this a bug? > > > > There are existing patterns that specify 'OptForSize' with "Requires", but > > they are not behaving as I expected. > > > > Example: > > // For scalar unary operations, fold a load into the operation > > // only in OptForSize mode. It eliminates an instruction, but it also > > // eliminates a whole-register clobber (the load), so it introduces a > > // partial register update condition. > > def : Pat<(f32 (fsqrt (load addr:$src))), > > (VSQRTSSm (f32 (IMPLICIT_DEF)), addr:$src)>, > > Requires<[HasAVX, OptForSize]>; > > > > This is generated: > > vsqrtss (%rdi), %xmm0, %xmm0 > > > > regardless of whether I specify -Os or -O1 with clang. > > You might want to take a look at the Mips target, it has a > class called PredicateControl defined in Mips.td, which > handles merging predicates together into a single list. > > Maybe you could do something similar for x86. > > -TomThat's right, it's solving the same problem. I added it after I found several defs that attempted to add predicates but accidentally removed some of the existing ones at the same time. The root of the problem is the way tablegen processes the declarations and assignments. tablegen creates an empty record and applies the subclasses in left-to-right order. Then it applies any 'let Foo = Bar in' statements. So given this code: let Predicates = [OptForSize] in { def : Pat<(v2f64 (X86VBroadcast (loadf64 addr:$src))), (VMOVDDUPrm addr:$src)>, Requires<[Foo]>, Requires<[Bar]>; } the value of Predicates in the record goes through the following values: * Undefined // Initial empty record * [] // The Pat has been applied * [Foo] // The first Requires<> has been applied. * [Bar] // The second Requires<> has been applied. * [OptForSize] // The let Predicates = ... in has been applied.
Maybe Matching Threads
- [LLVMdev] predicates vs. requirements [TableGen, X86InstrInfo.td]
- [LLVMdev] X86 LowerVECTOR_SHUFFLE Question
- [LLVMdev] X86 LowerVECTOR_SHUFFLE Question
- [LLVMdev] Possible bug in getCallPreservedMask for CallingConv::Intel_OCL_BI
- [LLVMdev] LLVM backends instruction selection